Question

I am using the client object model to query a record in a list. It filters by the Title which is unique so I would expect it to only return one record but it is returning the entire list.

Here's the code:

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;

What's wrong with this? Why is it returning the entire list?

Was it helpful?

Solution

You're missing the query node around the .

It should look like this

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

CAML is sometimes more than strict! Just give it a try.

Thorsten

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top