Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can I dinamically generate/specify a list of item fields I want to load when querying a list using the Client OM?

This is possible to do using the tag on the CAML query, but this loads additional unwanted fields, making the payload bigger. See here: http://blogs.technet.com/b/speschka/archive/2009/11/01/using-the-sharepoint-2010-client-object-model-part-3.aspx

Here's the testing code im using:

  ClientContext clientContext = new ClientContext("http://myserver/sites/mysite");
Web site = clientContext.Web;

List list = clientContext.Web.Lists.GetByTitle("MyList");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View Scope='RecursiveAll'><RowLimit>100</RowLimit></View>";
ListItemCollection listItems = list.GetItems(camlQuery);

clientContext.Load(listItems,
      items => items.ListItemCollectionPosition,
      items => items.Include(
              item => item["ID"],
              item => item["Title"]
              ));

clientContext.ExecuteQuery();

What I want to do is to generate the lambda expression's for the Include method at runtime. Still no luck. Every solution I try gives me error "The query expression is not supported."

share|improve this question
    
Could you create a lambda expression for include dynamically? I need the same. Thanks, Manvir –  user14132 Jan 15 '13 at 5:55

2 Answers 2

I had the same problem. The solution I found was to import the Microsoft.SharePoint.Client namespace.

using System;
using System.Linq;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

If the using for the Microsoft.SharePoint.Client namespace without the alias not is in the list you get the error as you mentiont in your question.

share|improve this answer

I found its resolution. Use LoadQuery instead of Load. Pls see complete solution here http://www.manvir.net/invalidqueryexpressionexception-the-query-expression-is-not-supported/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.