gpt4 book ai didi

c# - 如何从 CRM 中获取超过 5000 个实体

转载 作者:太空狗 更新时间:2023-10-29 18:16:01 25 4
gpt4 key购买 nike

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

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.Entities 中最多 5000 个元素。我知道 CRM 中有更多实体。如何检索所有实体?

最佳答案

使用 fetch XML 一次只能取回 5000 条记录。

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

Sample: Use FetchXML with a paging 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:

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

关于c# - 如何从 CRM 中获取超过 5000 个实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26754760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com