Skip to content

[DefaultOrderBy]

Allows setting of the default manner in which the data returned to the client will be sorted. Multiple fields can be used to sort an object by specifying an index.

This affects the sort order both when requesting a list of the model itself, as well as when the model appears as a child collection off of a navigation property of another object.

In the first case (a list of the model itself), this can be overridden by setting the orderBy or orderByDescending property on the TypeScript ListViewModel - see TypeScript List ViewModels.

Example Usage

c#
public class Person
{
    public int PersonId { get; set; }
    
    public int DepartmentId { get; set; }

    [DefaultOrderBy(FieldOrder = 0, FieldName = nameof(Department.Order))]
    public Department Department { get; set; }
    
    [DefaultOrderBy(FieldOrder = 1)]
    public string LastName { get; set; }
}
c#
public class Person
{
    public int PersonId { get; set; }
    
    public int DepartmentId { get; set; }

    [DefaultOrderBy(FieldOrder = 0, FieldName = nameof(Department.Order))]
    public Department Department { get; set; }
    
    [DefaultOrderBy(FieldOrder = 1)]
    public string LastName { get; set; }
}

Properties

// Also settable via constructor parameter #1
public int FieldOrder { get; set; } = 0; 

Specify the index of this field when sorting by multiple fields.

Lower-valued properties will be used first; higher-valued properties will be used as a tiebreaker (i.e. .ThenBy(...)).

// Also settable via constructor parameter #2
public OrderByDirections OrderByDirection { get; set; } = OrderByDirections.Ascending;

Specify the direction of the ordering for the property.

Enum values are:

  • DefaultOrderByAttribute.OrderByDirections.Ascending
  • DefaultOrderByAttribute.OrderByDirections.Descending

public string FieldName { get; set; }

When using the DefaultOrderByAttribute on an object property, specifies the field on the object to use for sorting. See the first example above.


Coalesce is a free and open-source framework created by IntelliTect to fill our desire to create better apps, faster. IntelliTect is a high-end software architecture and development consulting firm based in Spokane, Washington.

If you're looking for help with your software project, whether it be a Coalesce application, other technologies, or even just an idea, reach out to us at info@intellitect.com — we'd love to start a conversation! Our clients range from Fortune 100 companies to local small businesses and non-profits.