Link Search Menu Expand Document

OrderField


This is the class that is being used to define an ordering of the results from any fetch operations (i.e.: Query, QueryAll or BatchQuery).

Creating an Instance

var orderBy = new OrderField("Id", Order.Ascending);

Or by descending.

var orderfield = new OrderField("Id", Order.Descending);

Ascending Method

You can also create by using the Ascending method.

var field = OrderField.Ascending<Customer>(c => c.Id);

Descending Method

Also by using the Descending method.

var fields = OrderField.Descending<Customer>(c => c.Id);

Parse Expression

You can also extract by parsing an expression.

var field = OrderField.Parse<Person>(e => e.Id, Order.Ascending);

Or by descending.

var field = OrderField.Parse<Person>(e => e.Id, Order.Descending);

Parse Object

You can also extract by parsing an anonymous object.

var fields = OrderField.Parse(new
{
    Id = Order.Ascending
});

Or by multiple columns.

var fields = OrderField.Parse(new
{
    LastName = Order.Ascending,
    FirstName = Order.Descending
});

Usability

Simply pass it on the operations like below.

var orderBy = new OrderField("Id", Order.Ascending);
using (var connection = new SqlConnection(connectionString0))
{
    var people = connection.QueryAll<Person>(orderBy: orderBy);
}