其他分享
首页 > 其他分享> > Dynamics CRM - 關於 QueryExpression 的分頁查詢

Dynamics CRM - 關於 QueryExpression 的分頁查詢

作者:互联网

      在 QueryExpression 中可以使用 PagingInfo 類來做分頁查詢,代碼參考如下:

 1 QueryExpression q = new QueryExpression("account");
 2 q.ColumnSet = new ColumnSet(true);
 3 q.Criteria.AddCondition("name", ConditionOperator.NotNull);
 4 
 5 PagingInfo pageInfo= new PagingInfo();
 6 pageInfo.Count = 5000;//最大值每頁5000條記錄
 7 pageInfo.PageNumber = 1;
 8 pageInfo.PagingCookie = null;
 9 
10 q.PageInfo = pageInfo;
11 while (true)
12 {
13     var resultList = service.RetrieveMultiple(q);
14     foreach (var item in resultList.Entities)
15     {
16         //do something
17     }
18 
19     if(resultList.MoreRecords)//如果後續還存在記錄,則查詢下一頁,否則結束查詢
20     {
21         q.PageInfo.PageNumber++;
22         q.PageInfo.PagingCookie = resultList.PagingCookie;
23     }
24     else
25         break;
26 }

 

标签:關於,resultList,QueryExpression,PagingCookie,new,查詢,pageInfo
来源: https://www.cnblogs.com/Sunny20181123/p/15308147.html