10

I'm trying to pull all Projects information from SharePoint using Client Side Object Model (CSOM). Here is how I'm getting Projects information:

projectContext.Load(projectContext.Projects,
    c =>
        c.Where(p => p.Id == new Guid(id))
            .IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
                f => f.StartDate, f => f.FinishDate, f => f.PercentComplete, f => f.Description));

projectContext.Load(projectContext.LookupTables, c => c.Include(f => f.Id, f => f.Entries));
projectContext.Load(projectContext.Web.SiteUsers);
projectContext.ExecuteQuery();

However, I also need to retrieve the FieldValues property from those projects, and I can't figure out how to include it in the same query. I found how to do it on the project level after I retrieved projects in from the code above, like this:

var pubProject = project.IncludeCustomFields;
projectContext.Load(pubProject);
projectContext.Load(pubProject.CustomFields);

projectContext.ExecuteQuery();

var fieldValues = pubProject.FieldValues;

Now pubProject will contain FieldValues information, but using that approach for all projects becomes too slow (it takes 1 - 4 seconds to make a call to SharePoint), since I need to make an additional request for each project and best practice for CSOM is to make as few calls as possible.

If I include FieldValues in the include fields, like this:

projectContext.Load(projectContext.Projects,
    c =>
        c.Where(p => p.Id == new Guid(id))
            .IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
                f => f.StartDate, f => f.FinishDate, f => f.PercentComplete, f => f.Description, f => f.FieldValues));

I'm getting following error:

The query expression 'f.FieldValues' is not supported.

Thriggle
  • 7,009
  • 2
  • 26
  • 37
Vlad Bezden
  • 83,883
  • 25
  • 248
  • 179

1 Answers1

0

I think you need to put f => f.CustomFields in your .IncludeWithDefaultProperties statement instead of f.FieldValues -- Loading CustomFields should cause FieldValues to be populated

willman
  • 1,191
  • 1
  • 7
  • 20