是否可以计算给定实体中的所有行,绕过 5000 行限制并绕过页面大小限制?
我不想在一个请求中返回超过 5000 行,而只想返回给定实体中所有行的计数。
根据 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.
我试过这个:
GET [Organization URI]/api/data/v9.0/accounts/?$count=true
还有什么办法吗?
最佳答案
更新:
最新发布的 v9.1 具有直接实现此功能的功能 - RetrieveTotalRecordCount
————————————————————————————————
不幸的是,我们必须选择这条路线之一来根据限制内的预期结果识别记录数。
1.如果小于5000,使用这个: (你已经试过了)
GET [Organization URI]/api/data/v9.0/accounts/?$count=true
2. 50000以下,用这个:
GET [Organization URI]/api/data/v8.2/accounts?fetchXml=[URI-encoded FetchXML query]
超出限制会报错:
AggregateQueryRecordLimit exceeded. Cannot perform this operation.
示例查询:
<fetch version="1.0" mapping="logical" aggregate="true">
<entity name="account">
<attribute name="accountid" aggregate="count" alias="count" />
</entity>
</fetch>
使用 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.最后的手段是迭代
@odata.nextLink
并使用代码变量( code example to query the next page )计算每个页面中的记录
关于odata - 计算 Dynamics CRM Online web api (ODATA) 中的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51543802/