Show/Hide Toolbars

TMS Aurelius Documentation

Navigation: Queries

Paging Results

Scroll Prev Top Next More

Aurelius provides methods the allows you to limit query results at server level. It's the equivalent of "SELECT TOP" or "SELECT..LIMIT" that some databases use (note this is just an analogy, TMS Aurelius will make sure to build the proper SQL statement for each database according to the supported syntax).

 

You can limit the number of objects retrieved by using the Take method of TCriteria object:

 

Results := Manager.Find<TCustomer>
  .OrderBy('Name')
  .Take(50)
  .List;

 

The previous code will retrieve the first 50 TCustomer objects, ordered by name. Using Take(0) will return an empty result. Using Take(-1) is equivalent to not using Take method at all, meaning all records will be returned. Values below -2 (including) are not allowed and might cause errors.

 

You can skip the first N objects retrieved by using Skip method:

 

Results := Manager.Find<TCustomer>

  .OrderBy('Name')

  .Skip(10)

  .List;

 

The previous will retrieve customers ordered by name, by will omit the first 10 customers from the list. Using Skip(0) is equivalent to not using Skip method at all, since it means skipping no records. Negative values are not allowed and might cause errors.

 

Although you can use Skip and Take methods without specifying an order, it often doesn't make sense.

 

Skip and Take methods are often used for paging results, i.e., returning objects belonging to an specific page. The following code exemplifies how to return objects belonging to the page PageIdx, with PageSize objects in each page:

 

Results := Manager.Find<TCustomer>

  .OrderBy('Name')

  .Skip(PageIdx * PageSize)

  .Take(PageSize)

  .List;