简体   繁体   中英

CAML Query not returning rows

I'm sure this is obvious to someone else, but I cannot work out why this CAML query is not returning rows.

The list has 5 items, the ItemCount on the SP.Client.List confirms this, however when we try to query the list via CAML, we get 0 rows back in the ListItemCollection

ClientContext context = GetContext();
            Microsoft.SharePoint.Client.List testList = context.Web.Lists.GetByTitle("Customers");
            context.Load(testList);
            context.ExecuteQuery();
            Console.WriteLine(testList.ItemCount.ToString());


            CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
            ListItemCollection items = testList.GetItems(query);
            context.Load(items);
            context.ExecuteQuery();
            Console.WriteLine(items.Count.ToString());

您可以尝试使用Camlex.Client.dll NuGet创建CAML查询

var caml = "<View>" + CamlexNET.Camlex.Query().Where(ee => ee["CustomerRef"] == 1121).ToString() + "</View>";

The code below is working fine in my test environment.

ClientContext clientContext = new ClientContext("http://sp2013/sites/team");
Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("Customers");
clientContext.Load(spList);
clientContext.ExecuteQuery();

if (spList != null && spList.ItemCount > 0)
{
    Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml = @"<View>
                            <Query> 
                                <Where><Eq><FieldRef Name='CustomerRef' />
                                    <Value Type='Number'>1121</Value></Eq>
                                </Where> 
                            </Query> 
                            <ViewFields><FieldRef Name='CustomerRef' /></ViewFields> 
                        </View>";
    ListItemCollection listItems = spList.GetItems(camlQuery);
    clientContext.Load(listItems);
    clientContext.ExecuteQuery();
    Console.WriteLine(listItems.Count);
}

I suggest you check the "CustomerRef" field again.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM