When using SetFirstResult(start)
and SetMaxResults(count)
methods to implement paging I've noticed that the generated query only does a select top count * from some_table
and it does not take the start
parameter into account or at least not at the database level. It seems that if I instruct NHibernate to execute the following query:
var users = session.CreateCriteria<User>()
.SetFirstResult(100)
.SetMaxResults(5)
.List<User>();
105 records will transit between the database server and the application which will take care to strip the first 100 records. With tables containing many rows this could be a problem.
I've verified that with an SQLite database NHibernate takes advantage of the OFFSET
and LIMIT
keywords to filter results at the database level. I am aware that there's no equivalent of the OFFSET
keyword and Oracle's ROWNUM
in SQL Server 2000 but is there any workaround? How about SQL Server 2005/2008?