What I like in SharePoint Client Object model is that you can make batch queries. What I cannot find is if it's possible to get related items (linked by lookup field) in the same query?
An example would be: - A list Partners with fields: Title, Address, ZIP, City and Country (lookup to Countries) - A list Countries with fields: Title, Abbreviation, Continent (Lookup to Continents)
If I'd want to load also a Continent for each partner (cannot be done through related fields in Lookup column), I'd need to first load the list of partners and then afterwards an additional query to load countries for each of the partner. Is it possible to do this in one query?
Currently this goes something like this (unoptimized, just for demo purpose):
ClientContext ctx = new ClientContext("http://mydemospsite"); List lst = ctx.Web.Lists.GetByTitle("Partners"); List lstCountries = ctx.Web.Lists.GetByTitle("Countries"); CamlQuery qry = new CamlQuery() { ViewXml = "" }; ListItemCollection itms = lst.GetItems(qry); ctx.Load(itms); ctx.ExecuteQueryAsync((o, e) => { foreach(ListItem itm in itms) { ListItem itmCountry = lstCountries.GetItemById(((FieldLookupValue)itm["Country"]).LookupId); //Do whatever, link the item,... } ctx.ExecuteQueryAsync(null, null); }, (o, e) => { Dispatcher.BeginInvoke(() => { MessageBox.Show("Error"); }); });
The sample above is poor and serves only as an example of the problem. Is it possible to load also (only) related countries without running the ExecuteQueryAsync twice?