Skip to content

Sorting

Alan Hatter edited this page Jun 13, 2020 · 1 revision

Sort requests require paging or else you'll get a size limit exceeded if you have too many results. If you don't use the ToPage method in conjunction with an OrderBy / OrderByDescending, I create a page request behind the scenes that will use the ServerMaxPageSize from LdapConfiguration. Here's a basic example:

IQueryable<User> users = context.Query<User>()
    .Where(u => u.SamAccountName = "jdoe")
    .OrderByDescending(u => u.LastName)
    .Select(u => new User { CommonName = u.CommonName, FirstName = u.FirstName, LastName = u.LastName });

When performing a server side sort, I highly recommend you include a filter to narrow the results for the server to sort. If the sort is not successful I throw an LdapException indicating the reason for the failure. Most likely it will be "UnwillingToPerform".

Clone this wiki locally