NHibernate: how to select a root entity in a projection

Ayende describes a really great way to get the number of pages and a specific page of data in one query:

http://ayende.com/blog/2334/paged-data-count-with-nhibernate-the-really-easy-way

His method is as follows:

IList list = session.CreateQuery("select b, rowcount() from Blog b")
              .SetFirstResult(5)
              .SetMaxResults(10)
              .List();

The only problem is that this example is in HQL and I need to do the same in the ICriteria query. To achieve the equivalent with ICriteria, I need to do something like:

IList list = session.CreateCriteria<Blog>()
              .SetFirstResult(5)
              .SetMaxResults(10)
              .SetProjection(Projections.RootEntity(), Projections.SqlFunction("rowcount", NHibernateUtil.Int64))
              .List();

The problem is that there is no such thing as Projections.RootEntity (). Is there a way to select the root object as one of the projections in the projection list?

, , CriteriaTransform.TransformToRowCount(), - . , , SQL Server. . .

: ICriteria, ?

EDIT: :

https://nhibernate.jira.com/browse/NH-1372?jql=text%20~%20%22entity%20projection%22

https://nhibernate.jira.com/browse/NH-928

+5

All Articles