Saturday, January 9, 2010

Relational List & LINQ to SharePoint[Linq to SharePoint Deferred Loading]

To perform LINQ to SharePoint query first wee need to create SharePoint List Entities classes using SPMETAL.EXE . you can find SPMETAL.EXE  @ C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN ( SharePoint Installed Dir).

Here is the syntax to generate SharePoint List Entities.

SPMETAL /web:http://localhost:44119/ /namespace:SreeniSP2010Lists  /code:SreeniLinqSPCtx.cs

Please Refer the following blog post

http://mstecharchitect.blogspot.com/2009/12/linq-to-sharepoint-spmetalexe-part-i.html for more info.

My Two Custom List named States, Cities .

image

image

Linq to SharePoint Deferred Loading –Lazy Loading

When We query the list  of states , Linq To SharePoint Smart enough to select Related Items and returns it. this may be problem if we have long list of Cities and this will create performance hit. we can turn off this behavior  setting the   DeferredLoadingEnabled property.

 image

The following Debug Mode Screenshots shows that there were 5 items loaded for the statename kerala.

image

Linq to SharePoint Deferred is turned on by default. In order to turn it off, you can set the DeferredLoadingEnabled property to false.

image

The following code snippet shows how to disable LINQ TO SharePoint Deferred Loading. so that we can avoid loading related Items.

image

The following Debug Mode Screenshots shows there were no related items loaded for statename called Kerala.

image

Query Result after LINQ TO SharePoint Deferred Loading set to false. Now we can see there is no related items loaded.

image

Nandri(Thanks)

SreenivasaRagavan

No comments: