I'm using the SharePoint 2010 Managed Client Object Model to retrieve a list of listitems:
string formattedDate = theDate.ToString("yyyy-MM-ddTHH:mm:ssZ");
CamlQuery absenceQuery = new CamlQuery();
absenceQuery.ViewXml = "<View><Query>" +
"<Where><Eq><FieldRef Name='AbsenceDate'/><Value Type='DateTime' IncludeTimeValue='FALSE'>" + formattedDate + "</Value></Eq></Where>"
+ "</Query>"
+"<ViewFields>"
+ " <FieldRef Name='Employee' /><FieldRef Name='AbsenceDate' /><FieldRef Name='AbsenceTime' /><FieldRef Name='ContentType' />"
+ "</ViewFields>"
+"<RowLimit>2000</RowLimit></View>";
ListItemCollection absences = clientContext.Web.Lists.GetByTitle("Absences").GetItems(absenceQuery);
clientContext.Load(absences);
I need to include the ContentType in the results so I tried changing that last line to
clientContext.Load(absences,
items=> items.Include(
item=>item.ContentType,
item=>item.ContentType.Name
));
The ContentType Name was not included in the results. When I tried to access it throws PropertOrFieldNotInitializedException.
I found a link here http://msdn.microsoft.com/en-us/library/office/ee534956(v=office.14).aspx that says Because this example uses the Include(IQueryable, []) method, only the specified properties are available after query execution. Therefore, you receive a PropertyOrFieldNotInitializedException if you attempt to access other properties beyond those that have been specified. In addition, you receive this error if you attempt to use properties such as ContentType or ParentList to access the properties of containing objects.
Anybody know how to retrieve the Items with the contentType name?