Linq query across all sites and subsites on a sharepoint server?
I'm working on a we开发者_如何学Cbpart for a sharepoint 2010 installation. This has multiple sites, and each site has pages, and may have subsites, themselves with more pages and sites. I want to get a list of all pages in the entire installation that match a certain criteria (eg title == "Test"
).
I can do this using a CAML SPSiteDataQuery object and setting the 'Webs' property to <Webs Scope="Recursive" />
. Obviously this makes the query consider the current site and all subsites.
On the other hand I want to use linq2sp if possible as it will present an easier learning curve for other developers. Using SPMetal I can generate a DataContext for my site, and then can query it with linq, however this will only access pages in the root site.
Is there some way to control the scope of a Linq query so that it works across all pages in all of the sites?
thanks, S
Upon ... reflection ... it would appear that you (and all of us) are out of luck. LINQ to Sharepoint converts queries to SPQuery objects, which can only be used to query specific lists. SPSiteDataQuery is not used anywhere in the Microsoft.SharePoint.Linq assembly. I guess you could iterate over all Lists executing the same query but that would be awfully inefficient.
You can only scope specific lists to folders using the EntityList< TEntity>.ScopeToFolder method.
A possible workaround is to use a custom Sharepoint LINQ provider that supports cross-site queries like this one . I haven't used it so I can't vouch for it.
精彩评论