我正在尝试使用客户端对象模型 (CSOM) 从 SharePoint 中提取所有项目信息。以下是我获取项目信息的方式:
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();
但是,我还需要从这些项目中检索 FieldValues 属性,但我不知道如何将其包含在同一查询中。从上面的代码中检索项目后,我找到了如何在项目级别执行此操作,如下所示:
var pubProject = project.IncludeCustomFields;
projectContext.Load(pubProject);
projectContext.Load(pubProject.CustomFields);
projectContext.ExecuteQuery();
var fieldValues = pubProject.FieldValues;
现在 pubProject 将包含 FieldValues 信息,但对所有项目使用该方法变得太慢(调用 SharePoint 需要 1 - 4 秒),因为我需要为每个项目提出额外的请求以及最佳实践CSOM 就是尽可能少地调用。
如果我在 include
字段中包含 FieldValues,如下所示:
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));
我收到以下错误:
The query expression 'f.FieldValues' is not supported.
最佳答案
我认为您需要将 f => f.CustomFields
放入 .IncludeWithDefaultProperties
语句中,而不是 f.FieldValues
-- 加载 CustomFields
应导致填充 FieldValues
关于sharepoint - 如何在 CSOM 请求中包含项目的 FieldValues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29850494/