Read First Record

Syntax

GetFirst(filter, orderBy);

Arguments

filter

Expression<Func<T, bool>>

Criteria by which the records of the repository should be filtered.

This parameter must not be empty.

null

orderBy

Func<IQueryable<T>, IOrderedQueryable<T>>

Order in which the records should be listed.

This parameter is optional.

null

Description

Gets the first record from a repository that fulfills the criteria specified in the parameter filter.

If orderBy is not null, it first orders the records according to the attributes specified in the parameter orderBy before getting the first record from the newly ordered list.

Example

Example 1: Filtering records by only one criterion

The following program illustrates the function call with only one criterion:

var orderFirst = repo.GetFirst(x => x.ProductID == "ADAM-567-BTO");

Function will load the first record from the repository that has "ADAM-567-BTO" as Production ID and store the result into the variable "orderFirst".

Example 2: Filtering records by multiple criteria

The following program illustrates the function call with multiple criteria:

var orderFirst = repo.GetFirst(x => x.ProductID == "ADAM-567-BTO" 
                                 && x.Quantity > 10 
                                 && x.IsUrgent == true);

Function will load the first record from the repository that has "ADAM-567-BTO" as Production ID, has a Quantity of more than 10 and is Urgent, and store the result into the variable "orderFirst".

Example 3: Filtering records by multiple criteria with order

The following program illustrates the function call with multiple criteria and specified order:

r orderList = repo.Get(x => x.ProductID == "ADAM-567-BTO" 
                         && x.Quantity > 10, 
                       o => o.OrderBy(c => c.Timestamp);

Function will order the records by their Timestamp attribute, load the first record from the ordered repository that has "ADAM-567-BTO" as Production ID and a Quantity of more than 10 and store the result into the variable "orderFirst".

Last updated