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


 

Supongo que te gusta

Origin blog.csdn.net/qq_41863100/article/details/103138778
Recomendado
Clasificación