Pagination and ordering of results
Sometimes you do not want to use the results of a query as is. You might want to narrow down the number of records that a query is fetching or order them on a particular column. In this section, we will see how to manipulate the result set of a criteria query.
Narrowing down the number of records returned by a query
Many times we are only interested in a subset of records that can be returned by a query. On a criteria query or QueryOver, you can limit the maximum number of records returned by calling the SetMaxResults()
method as follows:
using (var transaction = database.Session.BeginTransaction()) { employees = database.Session.CreateCriteria<Employee>() .CreateCriteria("ResidentialAddress") .Add(Restrictions.Eq("City", "London")) .SetMaxResults(10) .List<Employee>(); transaction.Commit(); }
If the database server supports limiting results then...