O'Reilly logo

Learning NHibernate 4 by Suhas Chatekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required