"The query uses unsupported elements, such as references to more than one list, or the projection of a complete entity by using EntityRef/EntitySet."}
System.SystemException {System.InvalidOperationException}"
While using LINQ to SharePoint if you get this exception the possible reason is:
a) The LINQ query is using Except or Union or any possibly other operator/function (another example - Join) that performs action on two or more LINQ queries.
I recently encountered this while using Except and Union.
Cause: SharePoint tries to convert these into CAML queries but there are no equivalents in CAML. Hence the above error is generated.
Example:
var result1 = from x in dataContext.SharePointList where ....
var result2 = from...
var resultFinal = result1.Union<DataClass>(result2)
The above statement resultFinal would result in this error.
Solution: use ToList before using such function / operation:
var resultFinal = result1.toList<DataClass>.Union<DataClass>(result2.toList<DataClass>)
i.e. before Union - convert to a list using ToList which will avoid CAML generation for Union internally.
No comments:
Post a Comment