Friday 25 December 2015

Difference between clientcontext.load() and clientcontext.executeQuery()

our data resides in a remote location (our SharePoint server), so we cannot directly access it. In fact this is true even of any server-side programming, it is only less obvious.

When we call Load, we are only preparing our query. As this article states, in SQL terms think of it of building the SELECT statement.
The  ExecuteQuery , submits our prepared query to the remote server and retrieve the specified data.

The difference between ExecuteQuery and ExecuteQueryAsync is whether you will wait for the web request to return in-place (in the same execution path) or you will submit a callback function to handle the return when it does come back. It has an impact on how you will structure your code, but not so much on the end result.

So, to be clear:

No communication occurs with the remote server until you call ExecuteQuery or ExecuteQueryAsync
You can build up your query by calling Load multiple times, even for properies of different objects, and the client API will construct the appropriate query.
You can narrow down the exact properties to fetch so as to be as brief as possible in your web traffic
Basically these are typical client-server communication patterns, and not at all unique to SharePoint

Simply we can state : Load is to prepare query what you want from the server and executeQueryAsync/executeQuery is to get the data from the server

No comments: