You are here: Basics Operations & Concepts > Querying > Native Queries > Native Query Sorting

Native Query Sorting

Native Query syntax allows you to specify a comparator, which will be used to sort the results:

IList<Pilot> pilots = container.Query(
    delegate(Pilot p) { return p.Age > 18; },
    delegate(Pilot p1, Pilot p2) { return p1.Name.CompareTo(p2.Name); });
NativeQueriesSorting.cs: Native query with sorting
Dim pilots As IList(Of Pilot) = container.Query(Of Pilot)(AddressOf QueryForAdults, AddressOf SortByName)
NativeQueriesSorting.vb: Native query with sorting
Private Shared Function QueryForAdults(ByVal pilot As Pilot) As Boolean
    Return pilot.Age > 18
End Function

Private Shared Function SortByName(ByVal pilot1 As Pilot, ByVal pilot2 As Pilot) As Integer
    Return pilot1.Name.CompareTo(pilot2.Name)
End Function
NativeQueriesSorting.vb: Query and sort function