我使用SharePoint客户端对象模型查询Sharepoint中的列表,并需要在帮助程序集中动态创建Linq查询。
如何从列表< string>创建以下内容?列名称包含" Id","标题"," LinkFileName","状态" ?
context.Load(listItems, items => items.Include(
item => item["Id"],
item => item["Title"],
item => item["LinkFilename"],
item => item["Status"]
));
答案 0 :(得分:4)
非常感谢Manvir解决我问题的帖子:
http://www.manvir.net/invalidqueryexpressionexception-the-query-expression-is-not-supported/
将ClientContext.Load
替换为支持运行时构建表达式的ClientContext.LoadQuery
。
private static Expression<Func<ListItem, object>>[] CreateListItemLoadExpressions(List<string> viewFields)
{
List<Expression<Func<ListItem, object>>> expressions = new List<Expression<Func<ListItem, object>>>();
foreach (string viewFieldEntry in viewFields)
{
string fieldInternalName = viewFieldEntry;
Expression<Func<ListItem, object>> retrieveFieldDataExpression = listItem => listItem[fieldInternalName];
expressions.Add(retrieveFieldDataExpression);
}
return expressions.ToArray();
}