简体   繁体   English

计算 Dynamics CRM Online web api (ODATA) 中的所有行

[英]Counting ALL rows in Dynamics CRM Online web api (ODATA)

Is it possible to count all rows in a given entity, bypassing the 5000 row limit and bypassing the pagesize limit?是否可以计算给定实体中的所有行,绕过 5000 行限制并绕过页面大小限制?

I do not want to return more than 5000 rows in one request, but only want the count of all the rows in that given entity.我不想在一个请求中返回超过 5000 行,而只想返回给定实体中所有行的计数。

According to Microsoft, you cannot do it in the request URI:根据 Microsoft 的说法,您不能在请求 URI 中执行此操作:

The count value does not represent the total number of entities in the system. 

It is limited by the maximum number of entities that can be returned.

I have tried this:我试过这个:

GET [Organization URI]/api/data/v9.0/accounts/?$count=true

Any other way?还有什么办法吗?

Update:更新:

Latest release v9.1 has the direct function to achieve this - RetrieveTotalRecordCount最新版本 v9.1 有直接实现这个功能 - RetrieveTotalRecordCount

———————————————————————————— ————————————————————————————————

Unfortunately we have to pick one of this route to identify the count of records based on expected result within the limits.不幸的是,我们必须选择这条路线之一来根据限制内的预期结果识别记录数。

1. If less than 5000, use this: (You already tried this) 1.如果小于5000,用这个:(你已经试过了)

GET [Organization URI]/api/data/v9.0/accounts/?$count=true

2. Less than 50,000, use this: 2. 少于50,000,使用这个:

GET [Organization URI]/api/data/v8.2/accounts?fetchXml=[URI-encoded FetchXML query]

Exceeding limit will get error: AggregateQueryRecordLimit exceeded. Cannot perform this operation.超出限制将出现错误: AggregateQueryRecordLimit exceeded. Cannot perform this operation. AggregateQueryRecordLimit exceeded. Cannot perform this operation.

Sample query:示例查询:

<fetch version="1.0" mapping="logical" aggregate="true">
  <entity name="account">
    <attribute name="accountid" aggregate="count" alias="count" />
  </entity>
</fetch>

Do a browser address bar test with URI:使用 URI 进行浏览器地址栏测试:

[Organization URI]/api/data/v8.2/accounts?fetchXml=%3Cfetch%20version=%221.0%22%20mapping=%22logical%22%20aggregate=%22true%22%3E%3Centity%20name=%22account%22%3E%3Cattribute%20name=%22accountid%22%20aggregate=%22count%22%20alias=%22count%22%20/%3E%3C/entity%3E%3C/fetch%3E

The only way to get around this is to partition the dataset based on some property so that you get smaller subsets of records to aggregate individually.解决这个问题的唯一方法是根据某些属性对数据集进行分区,这样您就可以获得更小的记录子集来单独聚合。

Read more 阅读更多

3. The last resort is iterating through @odata.nextLink and counting the records in each page with a code variable ( code example to query the next page ) 3.最后一@odata.nextLink就是遍历@odata.nextLink ,用代码变量统计每页的记录数(查询下一页的代码示例

Use function RetrieveTotalRecordCount :使用函数RetrieveTotalRecordCount

If you want to retrieve the total number of records for an entity beyond 5000, use the RetrieveTotalRecordCount Function.如果要检索超过 5000 条实体的记录总数,请使用 RetrieveTotalRecordCount 函数。

Your query will look like this:您的查询将如下所示:

https://<your api url>/RetrieveTotalRecordCount(EntityNames=['accounts'])

The XrmToolBox has a counting tool that can help with this . XrmToolBox 有一个计数工具可以帮助解决这个问题。

Also, we here at MetaTools Inc. have just released an online tool called AggX that runs aggregates on any number of records in a Dynamics 365 Online org, and it's free during the beta release.此外,我们 MetaTools Inc. 刚刚发布了一个名为AggX的在线工具,该工具可以对 Dynamics 365 Online 组织中的任意数量的记录运行聚合,并且在测试版发布期间是免费的。

You may try OData's $inlinecount query option.您可以尝试OData 的$inlinecount 查询选项。 Adding only $inlinecount=allpages in the querystring will return all records, so add $top=1 in the URI to fetch only one record along with count of all records.在查询字符串中仅添加$inlinecount=allpages将返回所有记录,因此在 URI 中添加$top=1以仅获取一条记录以及所有记录的计数。

You URL will look like /accounts/?$inlinecount=allpages&$top=1您的 URL 将类似于/accounts/?$inlinecount=allpages&$top=1

For example, click here and the response XML will have the count as <m:count>11</m:count>例如, 单击此处,响应 XML 的计数为<m:count>11</m:count>

Note: This query option is only supported in OData version 2.0 and above注意:此查询选项仅在 OData 2.0 及更高版本中受支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM