2012-01-14 70 views
3

我正在使用客戶端對象模型來查詢列表中的記錄。它過濾標題是唯一的,所以我希望它只返回一個記錄,但它返回整個列表。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; 

這有什麼錯呢?爲什麼它會返回整個列表?

回答

3

你錯過了周圍的查詢節點。

它應該是這樣的

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

CAML有時比嚴格的多!試試吧。

Thorsten

相關問題