Core Concepts > Basic Queries

Order By

Results can be ordered either ascending or descending by using the Asc or Desc properties of a field expression (or any valid expression element). When not provided, order defaults to ascending. dbExpression supports ordering by any number of expression elements.

//select all people ordered by last name descending
IEnumerable<Person> people = db.SelectMany<Person>()
    .From(dbo.Person)
    .OrderBy(dbo.Person.LastName.Desc())
    .Execute();
//select all people ordered by gender type ascending and last name ascending
IEnumerable<Person> people = db.SelectMany<Person>()
    .From(dbo.Person)
    .OrderBy(
        dbo.Person.GenderType,
        dbo.Person.LastName
    )
    .Execute();
Previous
Joins

© 2024 dbExpression. All rights reserved.