NHibernate HQL's Equivalent to T-SQL's TOP Keyword

BuddyJoe picture BuddyJoe · Feb 17, 2009 · Viewed 12.4k times · Source

What is NHibernate HQL's Equivalent to T-SQL's TOP Keyword?

Also what is the non-HQL way for saying give me the first 15 of a class?

Answer

mookid8000 picture mookid8000 · Feb 17, 2009

It's actually pretty easy in HQL:

var top15 = session.CreateQuery("from SomeEntity")
                .SetFirstResult(0)
                .SetMaxResults(15)
                .List<SomeEntity>();

Don't know how to do this using the criteria API though.