簡體   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