Hi,
The code example you are referring to uses an aggregate type Fetch XML query. This query returns one single row in the result set, so the 5,000 records per page limit does not apply here.
In most cases SQL Server can execute an aggregate over several thousands of records in an eyeblink. If you do experience performance issues, you can consider creating custom table indexes.
Hope this helps.
Henk
If this post is an answer or helpful, please do not forget to vote!