How do I take the "top n" using NHibernate Criteria API?
Asked Answered
D

1

17

How do I take the "top n" using NHibernate Criteria API? Ideally I'd like to use detached criteria.

Downbow answered 20/7, 2010 at 6:13 Comment(1)
#619451Downbow
J
29

something like:-

criteria.SetFirstResult(1);
criteria.SetMaxResults(10);

Will take the first 10 results.

Junno answered 20/7, 2010 at 6:20 Comment(2)
SetFirstResult is not needed unless you need to skip records/pages.Garvy
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.Domiciliate

© 2022 - 2024 — McMap. All rights reserved.