Table of Contents


Pagination within Queries

Sometimes you are required to apply pagination to queries and show the first 10 or 20 matches only, however you need to get the total records so that it will make it possible to paginate through all records found.

Magentrix offers you a method in the query language to use for this purpose. Below, a sample code outlines how you can get the total records and the first page of the records at once:

var results = Database.Query<Account>()
  .Where(f => f.Industry = "Telecom")
  .Limit(10)
  .ToQueryResult();

// total number of records found
long totalRecords = results.Count;

//first 10 matches
List<Account> records = results.Records;

In the above example, the "ToQueryResult" method returns two values for a list of records found on the first page and also the number of total records found based on current query criteria.

In order to skip records and get the second or so on pages, you can use "Limit" method's second parameter, which is the skip. For example: Limit(10,10).