开发者

Sharepoint - LINQ vs Direct SPQuery

I am trying to find a optimized method for working with LINQ queries vs calling SPQuery for a select statement. The case in question is: I have a document library that has got to close 5000+ documents (arranged in folders) and I have a global cache of all document details for selected metadata queried and cached as "Document" custom entity. Our business users typically updated the document library in a decent frequency and code is available to clear and recreate this cache.

Now I am writing a new UI that would select and fetch all documents that match a particular "Keyword" (metadata). I have two options 1) Execute a CAML query against document library that would fetch me the results as SPListItem which I need to convert to "Document" entities (about 8 public strings of metadata)

OR

2) Query this big document library cache using LINQ and fetch the resulting "Document" entities.

Any technical expl开发者_StackOverflow社区anations on which is better and why from a SharePoint perspective would hugely help.

Plesae feel free to question my case for more information

thanks in advance Cheers


If you just want to get the cached items and no trip to the database is required then obviously your best bet is to query the cached Document entities.

On the other hand if you then need to get the entities from SharePoint then I would suggest using SPQuery to get the items in the first place.

I implemented similar functionality in a repository class I wrote for SharePoint data access.

ICollection<Document> list = 
            web.Lists[documentLibraryName].GetItems(query).Cast<SPListItem>().Select(
                doc => new Document(
                    doc["Title"].ToString(),
                    doc["Size KB"].ToString())).ToList();

The above is slightly different from my code but it outlines a neat way to convert to your Document entities after you execute the query.


I think you can also use PortalSiteMapProvider if you want to exploit cache for better performance.

PortalSiteMapProvider.GetCachedListItemsByQuery method can be used to query the list and also cache the query results. However, you should avoid using it if your query returns different data-sets at each time. For more detail check this out :

http://extreme-sharepoint.com/2012/07/17/data-access-via-caml-queries/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜