Documentation
SolutionDeveloperComplianceProjects
  • Getting Started
  • Technology
    • Application Framework
    • Object-Relational Mapping
    • Security Framework
    • Architecture Pattern
    • API Management
  • Environment
    • Development Tool
    • Database Server
    • Web Server
  • PRESENTATION
    • Design Material
    • HTML Helpers
    • Icon Images
    • Custom CSS
    • JQuery Plugin
      • DataTables
      • Tabs
      • Date Picker
      • Calendar
      • Chart
      • Treeview
    • Client Script
      • Open Modal
      • Close Modal
      • Handle return data
      • Load Content
      • Change Hash
      • Change Title
      • Get actual Hash
      • Get Content
      • Update Content
      • Delete Content
      • Get Partial Content
      • Get Partial Content Async
      • Update Partial Content
      • Update Partial Content Async
      • Delete Partial Content
      • Get Action
      • Update Action
      • Delete Action
      • Cascading Dropdown
      • Display Document
    • MVC View
  • BACKEND
    • Base Controller
    • Controller
    • Base Model
    • View Model
    • Class Utility
      • Constant Values
      • Global Properties
      • Option Helper
      • Setting Helper
    • Data Repository
      • Read Columns
      • Read All Columns
      • Read First Record
      • Read by Primary Key
      • Find Record
      • Insert Record
      • Update Record
      • Delete Entity
      • Delete by Criteria
      • Delete by Primary Key
      • Counting Record
      • Check Exist
      • Generate Row-Id
    • Unit Of Work
    • Data Entity
  • Application Features
    • Account Management
    • Navigation Editor
    • Access Control
  • Examples
    • Simple Page
    • Master Detail
    • Editor Template
Powered by GitBook
On this page
  • Syntax
  • Arguments
  • Description
  • Example
  • Example 1: Filtering records by only one criterion
  • Example 2: Filtering records by multiple criteria
  • Example 3: Filtering records by multiple criteria with order
  1. BACKEND
  2. Data Repository

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".

PreviousRead All ColumnsNextRead by Primary Key

Last updated 2 years ago