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