使用 linq 过滤带有子列表的共享点列表

Using linq to filter sharepoint-lists with sublists

我有一个问题,我的 LINQ 知识很少,无法解决。

我有一个包含字段列表的列表集合。 我只需要具有 hidden == false 属性的列表,以及具有描述 "Special Field" 的字段。

我尝试了以下方法...none 其中有效:

clientContext.Load(listCollection,
lists => lists
.Where(list => list.Hidden == false)
.SelectMany(list => list.Fields)
.Where(field => field.Description == "Special Field"));

var listQuery = from list in listCollection.Where(l => l.Hidden == false)
from field in list.Fields
where field.Description == "Special Field"
select list;

var listQuery2 = listCollection
.SelectMany(lists => listCollection)
.Where(l => l.Hidden == false)
.SelectMany(fields => fields.Fields)
.Where(f => f.Description == "Special Field"

所有后跟

var result = clientContext.LoadQuery(listQuery2);
clientContext.ExecuteQuery();

None 他们工作了。

我得到以下异常(对于最后一个查询,但消息与其他查询类似):

The query expression 'value(Microsoft.SharePoint.Client.ListCollection).SelectMany(lists => value(docma.Library.Classes.SharepointDataConnector+<>c__DisplayClass56_0).listCollection).Where(l => (l.Hidden == False)).SelectMany(fields => fields.Fields)' is not supported.

有人知道我做错了什么或如何让它工作吗?

我需要使用 2 个查询吗?

性能很重要。

提前致谢。

如错误所述Enumerable.SelectMany is not supported by LINQ to SharePoint provider

检索以下数据

I need only the lists with the properties hidden == false and that got fields with the description "Special Field".

您可以通过 ClientContext.LoadQuery method 使用以下查询:

var lists = ctx.Web.Lists;
var result = ctx.LoadQuery(lists.Where(list => list.Hidden == false).Include(l => l.Fields.Where(f => f.Description == "Special Field")));
ctx.ExecuteQuery();

var lists = ctx.Web.Lists;
var result = ctx.LoadQuery(lists.Where(list => list.Hidden == false).Include(l => l.Title,l => l.Fields.Where(f => f.Description == "Special Field").Include( f => f.Title, f => f.Description)));
ctx.ExecuteQuery();

您可以在其中指定 需要 returned 的属性,例如 List.TitleField.TitleField.Description 是这个案例

更新

对于 return 包含 特定 字段的列表,可以应用以下过滤器:

var foundLists = result.Where(l => l.Fields.Count > 0).ToList();