Queries Spanning Multiple Query Results

The following code block shows how to handle pagination and queries that span multiple query results.
SalesforceSession salesforceSession = new SalesforceSession(new LoginDetails("username@example.com", "salesforcePassword"));
 
LeadDataSource leadDataSource = new LeadDataSource(salesforceSession);
string[] requiredLeadFields = new string[] { "Id", "Name", "Email", "Description" };
 
QueryResultPager pager = leadDataSource.GetPager(requiredLeadFields);
 
Assert.IsTrue(pager.TotalRecordCount > 10000, "The total number of records");
 
var firstPage = pager.GetPage(salesforceSession, 0, 10); //Records 0 to 9
List<Lead> leads = leadDataSource.EntitysFromQueryResult<Lead>(firstPage);
 
var randomPage = pager.GetPage(salesforceSession, 30, 100); //Records 3000 to 3099
leads = leadDataSource.EntitysFromQueryResult<Lead>(randomPage);
 
randomPage = pager.GetPage(salesforceSession, 1, 150); //Records 150 to 299
leads = leadDataSource.EntitysFromQueryResult<Lead>(randomPage);
 
randomPage = pager.GetPage(salesforceSession, 17, 15); //Records 255 to 269
leads = leadDataSource.EntitysFromQueryResult<Lead>(randomPage);
 
randomPage = pager.GetRecords(salesforceSession, pager.TotalRecordCount - 101, pager.TotalRecordCount - 1); //The last 100 leads
leads = leadDataSource.EntitysFromQueryResult<Lead>(randomPage);