Aggregate Query limit exceeded?

若如初见. 提交于 2019-12-12 14:27:08

问题


I've got a 2 part question:

First question: I know that there is a query limit of 5,000 records when querying records, for performance reasons, but is there a limit when doing an aggregate query? If so, what is it? I need only to query the number of records and for one entity I can get a result of 39,000+ records, but for another entity I see an error message like:

System.ServiceModel.FaultException 1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: AggregateQueryRecordLimit exceeded. Cannot perform this operation. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).

I've been looking all over online but can't find anything on a query limit for aggregate/count queries.

Second question: Is there a simple way to query the COUNT of a large amount of records without a performance hit? I wouldn't think doing a count should require too much overhead. If there IS a limit, my idea was to implement paging in a loop and just retrieve the count for a given page while incrementing the page number each time until 0 records was returned. However, when I tried this, it seems to ignore the page and count attributes of the initial <Fetch> tag.

I'm wondering if there is a better/easier way to do this?


回答1:


I can't speak much to your first issue, but it looks like someone on MSDN may have found a workaround. See especially the linked forum post for the practical solution.

For the second question, COUNT is relatively easy to handle. See the MSDN article on FetchXML aggregates for lots of examples.

<fetch distinct='false' mapping='logical' aggregate='true'> 
    <entity name='opportunity'> 
       <attribute name='name' alias='opportunity_count' aggregate='count'/> 
    </entity> 
</fetch>

The generated SQL for that query will be as follows:

SELECT
    COUNT(*) AS opportunity_count
FROM
    Opportunity


来源:https://stackoverflow.com/questions/10131097/aggregate-query-limit-exceeded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!