繁体   English   中英

CAML查询未返回行

[英]CAML Query not returning rows

我确定这对其他人来说是显而易见的,但我无法弄清楚为什么此CAML查询未返回行。

该列表有5个项目,SP.Client.List上的ItemCount确认了这一点,但是当我们尝试通过CAML查询列表时,我们在ListItemCollection中返回了0行

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>";

下面的代码在我的测试环境中工作正常。

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);
}

建议您再次检查“ CustomerRef”字段。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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