Redaguoti

Bendrinti naudojant


Count rows using QueryExpression

Use the boolean QueryExpression.PageInfo.ReturnTotalRecordCount property to specify that the result include a count of all the records that meet the filter criteria, up to 5000. Use this when retrieving paged results to estimate the total number of pages to display.

You can't use the QueryExpression.TopCount property together with ReturnTotalRecordCount..

Example

When the ReturnTotalRecordCount property value is true, the EntityCollection returned from the RetrieveMultiple method includes values for the following properties:

Property Description
TotalRecordCount The total number of records up to 5000; otherwise the value is -1.
TotalRecordCountLimitExceeded true if the results of the query exceeds the total record count; otherwise, false.

The TotalRecordCountLimitExceeded value is useful when you need to calculate how many more paged requests you need to send to get all the results when TotalRecordCount equals 5000.

If your page size is less than the maximum and TotalRecordCount is equal to or less than 5000, you can calculate how many more paged requests you must send to get all the records.

When TotalRecordCountLimitExceeded is true and TotalRecordCount equals 5000, you can't perform this calculation.

Tip

If you want to get a total count of records with no filter, use the RetrieveTotalRecordCountRequest class. The data retrieved will be from a snapshot within the last 24 hours.

Next steps

Learn how to optimize performance.