Difference between LoadQuery() and LoadDataQuery() in SharePoint 2010

This SharePoint tutorial, we will discuss what is the difference between LoadQuery() and LoadDataQuery() in SharePoint 2010/2013.

The Client Object Model has two load methods: Load() and LoadQuery().

Load() method populates the client object directly with what it gets data from the server i.e. a collection object like ListItemCollection etc. But LoadQuery returns the data as a completely new collection in IEnumerable format.

The Collections that you load using the Load() method are eligible for garbage collection only when the client context variable itself goes out of scope whereas, in these collections go out of scope at the end of IEnumerable list.

The Load() method does an in-place loading of the data returned from the server. All of the data returned from the server is stored and tracked inside of the ClientContext object. The ClientContext tracks the object IDs of the items and properties returned from the server.

The LoadQuery() method returns the results as new objects. These objects are not part of the ClientContext and a result can be easily managed and discarded when not needed anymore.

Example LoadQuery() in SharePoint

var query = from list
in clientContext.Web.Lists
where list.Hidden != false
select list;
var result = clientContext.LoadQuery(query);
clientContext.ExecuteQuery();

Example Load() in SharePoint

var web = clientContext.get_web();
var lists = web.get_lists();
clientContext.Load(lists, 'Title');

You may like following SharePoint tutorials:

Here we learned what are the difference between LoadQuery() and LoadDataQuery() in SharePoint 2010.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>