Tuesday, 2 December 2014

Difference between Load and LoadQuery in client object model


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. Other major difference is that 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 where as, in these collections go out of scope at the end of IEnumerable list.

                        You might have noticed that the Client Object Model has two load methods, Load() and LoadQuery(). 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. For example if you call the server for the web object but do not return the title on the first call, you could subsequently call the server again for the title. The Title property is now filled in and ready to be used. This convenience does come with some trade-offs. For example, because the objects returned from the server are stored in the ClientContext object, it means that all of the data will only be garbage collected in the Silverlight application when the ClientContext object is cleaned out.


                     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 any more. Another difference between Load() and LoadQuery() is the type of queries you can write. The Client OM supports two types of queries: LINQ query syntax and method syntax. LINQ query syntax is a more natural declarative query language. This format is one that you are probably more familiar with and what people think of when they write LINQ queries. Listing 8.5 shows an example of a LINQ query to return visible Lists.

Reference:

http://techno-sharepoint.blogspot.in/2012/10/difference-between-load-and-loadquery.html

No comments:

Post a Comment