I am trying to use LINQ on a result i get from Client Object Model.
var rolesAssignments = context.Web.RoleAssignments;
context.Load(rolesAssignments,
roles => roles.IncludeWithDefaultProperties(role => role.Member,
role => role.RoleDefinitionBindings));
context.ExecuteQuery();
var hasAdmin = rolesAssignments.Select(x => x.RoleDefinitionBindings.Cast<RoleDefinition>().Select(y => y.RoleTypeKind == RoleType.Administrator)).Any();
I get:
{System.NotSupportedException: Invalid usage of query execution. The query should be executed by using ExecuteQuery method on the client context object.
However, when i rewrite this to use a nested foreach loop, it works fine.
From what i can see from my linq query, im not using any properties thats not loaded.
This is off the top of my head but it should give you the idea. You may get a complaint about the use of Any in the query. If so remove it and then check hasAdmin.Any() after the ExecuteQuery is complete.