A .NET job uses RetrieveMultiple with a QueryExpression to export all contacts from an environment that holds 60,000 of them, but the export file always contains exactly 5,000 rows. The code calls RetrieveMultiple once and writes the returned entities. What should the developer change?
Select an answer to reveal the explanation.
Short Explanation
Dataverse hands results back one page at a time, like a book. You've read page one and stopped. Keep turning pages while MoreRecords says there's more, and hand back the paging cookie so it knows where you left off.
Full Explanation
RetrieveMultiple returns results in pages, with a default page size of 5,000 rows for standard tables. The returned EntityCollection exposes MoreRecords, which indicates whether additional pages exist, and PagingCookie, which identifies the position for efficient retrieval of the next page. Code that must read all rows sets PageInfo on the QueryExpression, then loops: it processes the current page, and while MoreRecords is true it increments PageInfo.PageNumber, assigns the returned PagingCookie to PageInfo.PagingCookie and calls RetrieveMultiple again. This retrieves all 60,000 contacts in twelve pages. TopCount caps the number of rows a query returns and cannot exceed the maximum page size, so it cannot make one call return 60,000 rows. NoLock is a hint about database locking and has no effect on paging; it does not cause additional rows to be returned. Distinct removes duplicate rows from the results and never increases the number of rows; contacts are already unique by primary key. Exam caveat: the same principle applies to the Web API, which returns an @odata.nextLink URL that clients must follow until it is absent. Operational check: log the page number and row count for each iteration, confirm the loop ends when MoreRecords is false, and verify the export contains 60,000 rows.