load vs loadquery && ExecuteQuery vs ExecuteQueryAsync in sharepoint


Load 

Load() populate the client object directly with what it gets data from the server i.e. a sollection eg. ListItemCollection. Means Load() returns ListCollection.

LoadQuery

LoadQuery() returns the data as a new collection in IEnumerable format.
LoadQuery() is flexible than Load() when you are working with more than one query(i.e More than one list) because LoadQuery() returns data in IEnumerable<> format which is easy to acces.

Load

LoadQuery

Load method populates the data whatever it gets from the server.

Note: Mostly it is Useful for get single list

LoadQuery method populates the data in completely new object of the type – IEnumerable 

Note: Mostly it is Useful for multiple list

Example:

Var List = ClientContext.Web.Lists.GetByTitle("ListName");

ClientContext.Load(List);

ClientContext.ExecuteQuery();

Example:

IEnumerable ListCollection = ClientContext. LoadQuery (ClientContext.Web.Lists);

ClientContext.ExecuteQuery();

Object is loaded into ClientContext, it will be eligible for Garbage Collection only when that ClientContext is out of scope.  

The result is loaded in a completely new object , so it will be available for Garbage Collection as soon as IEnumerable object goes out of scope.




ExecuteQuery VS ExecuteQueryAsync

ExecuteQuery

ExecuteQueryAsync

synchronous call & Code wait until SharePoint send a response back (Only available in C#)

asynchronous call & code continues to execute and does not wait for SharePoint’s response (available in JSOM)

This is helpful when you want to conditionally execute the next steps based on response from the server.

You specify callback methods to catch the response from the server.

Syntax: ClientContext.ExecuteQuery()

Syntax: ExecuteQueryAsync(callback success,callback failure)


Comments

Popular posts from this blog

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

Add content type to SharePoint List/Library using REST API

A type named 'SP.Data. could not be resolved by the model error