Table of Contents


Query Options

 
QueryOptions allows you to support pagination, set sort expression or sort direction. You can also include related entities to load into the result-set as part of your query.
 
 
Below is the list of properties QueryOption provides:
 
  • SystemMode: a boolean value that dictates whether or not the query should be executed in system mode or user's context. Default is false.
  • SortExpression: a string value. You can pass the name of the field with which the result-set needs to be sorted.
  • SortDirection: an enum of ListSortDirection possible values are: 
    • ListSortDirection.Ascending
    • ListSortDirection.Descending
  • Skip: int, number of records to skip based on a given sort-expression and sort direction.
  • Take: int, number of records to load based on a given sort-expression and sort direction.
  • Includes: a comma-separated list of related entities based on relationship name; see example below.
  • IncludeDeletedItems: retrieve deleted records as well.

     

The example below shows how you can pass the QueryOptions:

var options = new QueryOptions { 
​  SortExpression = "Name", 
  SortDirection = ListSortDirection.Ascending, 
  Includes = "Contacts"
};

​var result = Database.Query<Account>(options)
    .Where(a => a.Name.Contains("media"))
    .ToList();