3

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

这是代码:

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;

这有什么问题?为什么它会返回整个列表?

4

1 回答 1

3

您缺少 .

它应该看起来像这样

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

CAML 有时不仅严格!试一试。

托尔斯滕

于 2012-01-14T15:12:59.550 回答