简体   繁体   中英

Is there a way how to get total count of entities of given type in CRM without paging

Suppose I have query like

var countAlias = "entity_count";
var query = FormattableString.Invariant($@" 
  <fetch distinct='false' aggregate='true'> 
    <entity name='{entityName}'> 
      <attribute name='createdon' alias='{countAlias}' aggregate='count'/> 
    </entity> 
  </fetch>");

var response = organizationService.RetrieveMultiple(new FetchExpression(query));
var entity = response.Entities.First();
var count = (int)((AliasedValue)entity[countAlias]).Value;

This works nicely unless there is more than 50K records - then it hits the aggregation limit. Is there a way how to query total count of entities in system without paging ?

Unfortunately, short answer is No .

Fetchxml is the only option to do aggregation like count, sum, etc - that too has 50k record limit due to performance consideration (upper limit can be bent for on-prem).

Query expression, LINQ to CRM doesn't support aggregation. That's why we got paging cookie as a choice from MS to iterate & count the records.

Alternatively, (unlikely) if you have reporting replication sql DB by pushing a data sync, Rollup count can be done with some jobs in timely manner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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