Client Object API – CRUD

http://msdn.microsoft.com/en-us/library/ee857094.aspx

In the case of Web Part, you write ECMAScript/Javascript/Jscript to implement COM;

Server side classes has “SP” prefix, such as “SPContext”, “SPList”;
Client side classes do not have “SP” prefix, such as “Web”, “ListItem”. (but server – SPContext, client – ClientContext)

Must add reference to two assemblies:
Microsoft.Sharepoint.Client.dll
Microsoft.Sharepoint.Client.RunTime.dll

There is no network traffic until the application calls the ExecuteQuery method. The call to the Load method does not actually load anything. Instead, it informs the client object model that when the application calls the ExecuteQuery method, you want to load the property values of the siteCollection object.

Can perform more complex queries; command is not executed until ExecuteQuery is issued.


LOAD method means to populate the lists; but ExecuteQuery actually send out the command.

If you try to use a property before it is populated by the ExecuteQuery method, the client object model throws a PropertyOrFieldNotInitializedException
exception.

Client object identity is valid only for a single ClientContext object. – Can’t have two ClientContext object!!!!

In COM, use lambda can reduce traffic!!!
Instead of loading the whole list, we load only Title & Description.

Use CAML; notice “Include“; because return type is ListItemCollections and you can’t specify which field to return.

You must use CAML when querying list items. No LINQ.

The LoadQuery method is similar in functionality to the Load method, except that in certain circumstances, the client object model can process the queries more efficiently and use memory more efficiently.

Notice that the LoadQuery method returns a new list collection that you can iterate through. The new list collection has a type of IEnumerable<List> instead of ListCollection.

LoadQuery can use multiple Include.

Updating Client Objects


First retrieve the records; and then loop to update it. Call Update(),
and then ExecuteQuery.

Deleting Client Objects

First retrieve the records; and then loop to delete it. Call Update(),
and then ExecuteQuery.

Delete the list.


SharePoint development guidelines indicate that you should not attempt to retrieve more than 2000 items in a single query. If this is a possibility in your application, consider using the RowLimit
element in your CAML queries to limit how much data that the client object model retrieves for your application. Sometimes you must access all items in a list that may contain more than 2000 items. If you must do so, then best practice is to page through the items 2000 at a time. This section presents an approach to paging using the ListItemCollectionPosition property.

Asynchronous Processing

ECMAScript/Silverlight
use asynchronous processing.
BeginInvoke
is the command to asynchronous process.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: