CRM QueryExpression的分页查询

#大于5000条数据分页查询QueryExpression
附上一个链接fetchxml分页和QueryExpression分页_菜刀居士的专栏-CSDN博客

public static void QueryPage(IOrganizationService service, QueryExpression query, Action<EntityCollection> action)
        {
            EntityCollection ec = null;
            int pageNumber = 1;
            do
            {
                query.PageInfo = new PagingInfo();
                query.PageInfo.Count = 5000;
                query.PageInfo.PagingCookie = (pageNumber == 1) ? null : ec.PagingCookie;
                query.PageInfo.PageNumber = pageNumber++;

                ec = service.RetrieveMultiple(query);
                if (ec != null && ec.Entities.Count > 0)
                {
                    action(ec);
                }
            } while (ec != null && ec.MoreRecords);
        }

使用方法

//例子
//有一个方法是这样的
public void Action(EntityCollection ec)
{
    Console.WriteLine(ec.Entities.Count);
}

//直接在Main里这样使用就行

QueryPage(service, query, Action);

#委托
插一个链接C#委托Action、Action<T>、Func<T>、Predicate<T> - 刘珍宝 - 博客园

Action    //直接Invoke调用

Action action = new Action(()=>Console.WriteLine("Hello"));
action.Invoke();

Action<T>    //直接调用里面的方法,可以有最多16个参数

Action<T> actoin = new Action<T>(要运行的方法名);
action(T类型的参数);

Func<T,Result>    //Result是返回的结果,最多16个参数

Func<int, int> func = new Func<int, int>(e => e + 5);
int n = func(6);   //n = 11;

Predicate<T>    //方法返回bool型

Predicate<string> t = new Predicate<string>(Compare);
string[] names = Array.FindAll(nameArray, t);

string fetchXml = @"<fetch version='1.0' output-format='xml-platform' nolock='true' mapping='logical'>                                        <entity name='{0}'>                                            <attribute name='{1}' />                                            <attribute name='{2}' />                                            <attribute name='{3}' />                                            <filter type='and'>                                                 <condition attribute='ave_key' operator='eq' value='{4}' />                                            </filter>                                         </entity>                                      </fetch>";


 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Admini$trat0r

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值