Sorting

  • OrderBy()

  • OrderByDescending()

  • ThenBy()

  • ThenByDescending()

  • Reverse()

// Some code
var itemList = context.Items.Where(x => !x.Items && x.DeliverySelection)
                            .OrderByDescending(x => x.Delivery.SubmissionDate)
                            //.ThenBy(x => x.Item);

Notes

  • If you want to call ThenBy, you should call OrderBy first or you need to cast it to IOrderedQueryable:

    var r = ((IOrderedQueryable<dynamic>)result).ThenBy(...);

  • ThenBy will work sorting the second fields in the order you want if there are fields in OrderBy with equal value

Last updated