What is the best way to get list items and their properties from an SP list using a client object model?
Here is the code I'm using.
string server = "http://localhost"; ClientContext context = new ClientContext(server); Web web = context.Web; var spList = web.Lists.GetByTitle("Contact"); CamlQuery query = new CamlQuery(); var items = spList.GetItems(query); context.Load(items, itema => itema.Include( item => item, item => item["CustomerId"])); context.ExecuteQuery(); Console.WriteLine("Items"); foreach (var item in items.ToList()) { context.Load(item); } context.ExecuteQuery(); foreach (var item in items) { foreach (var a in item.FieldValues) { Console.WriteLine(a.Key + ":" + a.Value.ToString()); } }
I want to remove the single liner foreach used to load the list of elements in the context, and, if possible, load the values โโof the element fields into the first execution request.
I tried using the following
context.Load(items, itema => itema.Include( item => item, item=> item.FieldValues, item => item["CustomerId"]));
which does not work.
Can anyone provide a cleaner solution?
Sandeep singh rawat
source share