One of the beautiful things about using LINQ to SharePoint to retrieve data from your lists and libraries is the absolute ease in which you can retrieve data from two or more lists which are joined by lookup fields.

For more information on setting up LINQ to SharePoint in your developmennt environment, check out my blog entitled Using SPMetal to Generate SharePoint 2013 LINQ Classes.

For example, I have two custom lists: Client (which contains ClientName, ClientLogo) and ClientQuote (which contains a Client lookup field, as well as Quote, ContactName, and ContactTitle).

With LINQ to SharePoint, I can easily write a query to retrieve information from both lists and populate a custom object called ClientQuotes:

If I were to use this in a custom web part, I would get the following error: The query uses unsupported elements, such as references to more than one list, or the projection of a complete entity by using EntityRef/EntitySet.

This error can be resolved by one simple adjustment:

What this does is force immediate query evaluation and breaks the query into two steps.

Advertisements