Sharepoint客户端对象模型查询过滤器不工作

问题描述:

我正在使用客户端对象模型来查询列表中的记录。它过滤标题是唯一的,所以我希望它只返回一个记录,但它返回整个列表。Sharepoint客户端对象模型查询过滤器不工作

下面的代码:

FieldLookupValue result = new FieldLookupValue(); 
List list = web.Lists.GetByTitle(lookupSourceList); 
var query = new CamlQuery 
       { 
        ViewXml = 
         string.Format(
          "<View><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>{0}</Value></Eq></Where></View>", 
          lookupValue) 
       }; 
var ls = list.GetItems(query); 
ctx.Load(ls, li => li); 
ctx.ExecuteQuery(); 
if (ls.Count == 1) 
{ 
    result.LookupId = ls[0].Id; 
} 

return result; 

这有什么错呢?为什么它会返回整个列表?

你错过了周围的查询节点。

它应该是这样的

<View> 
    <Query> 
    <Where> 
    <!-- --> 
    </Where> 
    </Query> 
</View> 

CAML有时比严格的多!试试吧。

Thorsten