When you need to access the Id property from a collection of ListItems, e.g.
foreach(ListItem li in <some ListItemCollection>)
{
int ItemID = li.Id;
}
and are using a lambda expression to return an optimized payload, be sure to request the ID field as “Id” rather than “ID”, otherwise a PropertyNotInitialized exception will occur.
So do this (where ctx is a ClientContext object):
ctx.Load(_listItems, li => li.Include(
i => i["Id"],
i => i["Item"],
i => i["Description"],
i => i["Event"],
i => i["User"],
i => i["Occurred"],
i => i["Outcome"],
i => i["List"]));
Not this:
ctx.Load(_listItems, li => li.Include(
i => i["ID"],
i => i["Item"],
i => i["Description"],
i => i["Event"],
i => i["User"],
i => i["Occurred"],
i => i["Outcome"],
i => i["List"]));
Filed under: C#, Managed Client API, SharePoint, Silverlight Tagged: ID, lambda, Managed Client API, Optimization
