首页 > 其他 > 详细

Dynamic 分页查询

时间:2021-09-13 12:48:37      阅读:31      评论:0      收藏:0      [点我收藏+]

 

//前端
//单次查询的个数
int pageSize = 5000;
//第几页
int pageIndex = 1;
var ectemp= new EntityCollection();//临时的实体集合
var ec = new EntityCollection();//查询数据的实体集合
do
{
    var fetchxml = string.Format(@"<fetch version=‘1.0‘ page=‘{0}‘ count=‘{1}‘ output-format=‘xml-platform‘ mapping=‘logical‘ distinct=‘false‘>
<entity name=‘实体名称‘>
<attribute name=‘查询的字段名‘ />
<attribute name=‘查询的字段名‘ />
<order attribute=‘排序字段‘ descending=‘false‘ />
</entity>
</fetch>", pageIndex, pageSize);
    ectemp= CRMService.RetrieveMultiple(new FetchExpression(fetchxml));
    if (ectemp?.Entities?.Count > 0)
    {
        foreach (var entity in ectemp.Entities)
        {
            ec.Entities.Add(entity);
        }
        pageIndex++;//页数++
    }
    else
    {
        break;//如果第一次没查到数据直接跳出
    }
} while (ectemp!= null && ectemp.MoreRecords);//判断查询是否还有数据

后端

//单次查询的个数
int pageSize = 5000;
//第几页
int pageIndex = 1;
var ec = new EntityCollection();//查询数据的实体集合
QueryExpression qe = new QueryExpression("实体名称");
qe.ColumnSet = new ColumnSet(true);
//按照时间进行排序
qe.Orders.Add(new OrderExpression("createdon", OrderType.Descending));
//分页查询
qe.PageInfo = new PagingInfo()
{
	Count = pageSize,
	PageNumber = pageIndex
};
do
{
    ec= CRMService.RetrieveMultiple(qe);
    if (ec?.Entities?.Count > 0)
    {
        qe.PageInfo.PageNumber++;//页数++
        qe.PageInfo.PageCookie = ec.PagingCookie;//页数++
    }
    else
    {
        break;//如果第一次没查到数据直接跳出
    }
} while (ec!= null && ec.MoreRecords);//判断查询是否还有数据

Dynamic 分页查询

原文:https://www.cnblogs.com/LanHai12/p/15257938.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!