How do I take the "top n" using NHibernate Criteria API? Ideally I'd like to use detached criteria.
Asked
Active
Viewed 8,888 times
16
-
http://stackoverflow.com/questions/618951/best-way-to-use-hibernate-for-complex-queries-like-top-n-per-group – Ben Aston Jul 20 '10 at 06:15
1 Answers
27
something like:-
criteria.SetFirstResult(1);
criteria.SetMaxResults(10);
Will take the first 10 results.

George Stocker
- 57,289
- 29
- 176
- 237

Rippo
- 22,117
- 14
- 78
- 117
-
5SetFirstResult is not needed unless you need to skip records/pages. – Diego Mijelshon Jul 20 '10 at 14:40
-
Doesn't work well when you have a one to many mapping for that entity. You can transform it after to get the dinctinct root entity but even still I'd like to be able to say, Nhibernate, give me the top 200 root entities with the hydrated children. – Eric Jul 09 '15 at 00:50