4

How can I dynamically 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: blog

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."

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

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.

0

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/

  • Its is best practice here to put some piece of code or information along with the reference/source link, and not just providing urls, some ppl might have other sites blocked, so its better they can read the stuffs here itself – Gaurravs Jan 21 '16 at 4:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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