views:

187

answers:

1

I'm working on a webpart 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

+1  A: 

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.

Panagiotis Kanavos
Blast, I suspected that might be the answer. Currently I've moved back to using the CAML approach, but I suspect this will need to be aggressively optimised at some point in the future. Thanks!
Stark
After the deep reflection I suspect L2SP will not support cross-site queries anytime soon (ie until the next version). SPQueries are used everywhere to load one list at a time. It seems the logic behind L2SP is one list - one Entity, as if Sharepoint were a database! Changing this either to support cross-site queries or queries on content types would be too big a change to roll out in a Service Pack.Deeply disappointed ....
Panagiotis Kanavos