I would like to reduce the no of fields that I get from CAML query. The List has more than 100 fields, which is causing a lot of performance issues.
In SSOM the SPQuery object has a query.ViewFieldsOnly = true;
. Currently I am querying SharePoint online using CSOM i.e. using c#. I do not get the ViewFieldsonly property.
Following is the code I use to get the ListItem
ClientContext context = new ClientContext("http://SiteUrl");
ListCollection lcoll = context.Web.Lists;
context.Load(lcoll);
context.ExecuteQuery();
lst = lcoll.Where(x => x.Title == ListName).FirstOrDefault();
CamlQuery cQuery = new CamlQuery();
cQuery.ViewXml ="<View>"+
"<Query>"+
"<Where><Eq>"+
"<FieldRef Name='MyName'/>"
"<Value Type='Text'>John"+
"Ranger</Value>"+
"</Eq></Where>"+
"</Query>"+
"<ViewFields>"+
"<FieldRef Name='MyName'/>"+
"<FieldRef Name='Title' />"+
"<FieldRef Name='ID' />"+
"</ViewFields></View>";
ListItemCollection licoll = lst .GetItems(cQuery);
context.Load(licoll);
context.ExecuteQuery();
ListItem item = licoll.Where(i => i[MyName].ToString()== email).FirstOrDefault();
context.Load(item);
context.ExecuteQuery();
Using the CAML query gives me one list item but with 179 fields. I only want the three fields that I have specified in the CAML query.