找不到 Linq to Sharepoint "where"子句



你好叠花,

我第一次尝试使用 LINQ to Sharepoint,但我的 where 关键字无法识别:"找不到源类型'Microsoft.SharePoint.SPList'的查询模式的实现。 '哪里'找不到"。

这是请求:

using System.Linq;
[...]
  var query = from item in listToQuery
              where item.Site == _siteToQuery
              && item.ReportType == _recordTypeToQuery
              && item.Date == stringDate
              select item;
  Result = listToQuery.GetItems(query);

listToQuery 和 Result 是两个 SPListItemCollection。

为什么在哪里不被识别?

很正常。SharePoint 对象不实现 Linq 查询,因此这就是出现此异常的原因。

若要查询 SharePoint 列表,需要使用 CAML 查询(具有 SPQuery 类型的对象(您可以在互联网上找到许多关于"如何以编程方式查询 SharePoint 列表"的文档

但是,如果您仍然想在 SharePoint 上使用 LINQ,则可以使用 SPMetal