如何从CRM中获取5000多个实体 [英] How to fetch more than 5000 entities from CRM

查看:121
本文介绍了如何从CRM中获取5000多个实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从控制台应用程序查询MS Dynamics CRM Online:

I'm querying MS Dynamics CRM Online from my console app:

public EntityCollection GetEntities(string entityName)
{
    IOrganizationService proxy = ServerConnection.GetOrganizationProxy();

    string request = string.Format("<fetch mapping ='logical'><entity name = '{0}'></entity></fetch>", entityName);
    FetchExpression expression = new FetchExpression(request);
    var mult = proxy.RetrieveMultiple(expression);

    return mult;
}

此代码最多只返回 mult中的5000个元素实体。我知道CRM中还有更多实体。
如何检索所有实体?

This code only returns maximum of 5000 elements in mult.Entities. I know there are more entities in CRM. How to retrieve all entites?

推荐答案

您只能在以下位置获取5000条记录

You can only get back 5000 records at a time using fetch XML.

要获取更多记录,您必须使用分页cookie,请参见此处:

To get more records, you have to use a paging cookie, see here:

示例:将FetchXML与分页Cookie一起使用

相关的代码位:

// Define the fetch attributes.
// Set the number of records per page to retrieve.
int fetchCount = 3;
// Initialize the page number.
int pageNumber = 1;
// Specify the current paging cookie. For retrieving the first page, 
// pagingCookie should be null.
string pagingCookie = null;

修改了主循环,因为该示例似乎并没有更新分页cookie:

The main loop modified, since the sample doesn't seem to do update the paging cookie:

while (true)
{
    // Build fetchXml string with the placeholders.
    string xml = CreateXml(fetchXml, pagingCookie, pageNumber, fetchCount);

     FetchExpression expression = new FetchExpression(xml);
     var results = proxy.RetrieveMultiple(expression);

    // * Build up results here *

    // Check for morerecords, if it returns 1.
    if (results.MoreRecords)
    {
        // Increment the page number to retrieve the next page.
        pageNumber++;
        pagingCookie = results.PagingCookie;
    }
    else
    {
        // If no more records in the result nodes, exit the loop.
         break;
    }
}

我个人倾向于使用LINQ而不是FetchXML,但是值得一提的是Lasse V. Karlsen所说的话,如果您向用户显示此信息,则可能要进行某种分页(使用FetchXML或LINQ)

I personally tend to use LINQ rather than FetchXML, but it's worth noting what Lasse V. Karlsen said, if you are presenting this information to the user, you probably want to be doing some kind of paging (either in FetchXML or LINQ)

这篇关于如何从CRM中获取5000多个实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆