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", ...
Get Learning NHibernate 4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.