NHibernate: How to select the root entity in a projection -


ayende describes great way page count, , specific page of data in single query here:

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

his method looks like:

ilist list = session.createquery("select b, rowcount() blog b")               .setfirstresult(5)               .setmaxresults(10)               .list(); 

the problem example in hql, , need same thing in icriteria query. achieve equivalent icriteria, need like:

ilist list = session.createcriteria<blog>()               .setfirstresult(5)               .setmaxresults(10)               .setprojection(projections.rootentity(), projections.sqlfunction("rowcount", nhibernateutil.int64))               .list(); 

the problem there no such thing projections.rootentity(). there way select root entity 1 of projections in projection list?

yes, know use criteriatransform.transformtorowcount() require executing query twice - once results , once row count. using futures may little reducing 1 round-trip, it's still executing query twice on sql server. intensive queries unacceptable. want avoid overhead, , return row count , results in same query.

the basic question is: using icriteria, there way select root entity , other projection @ same time?

edit: related links:

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

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

i implemented rootentityprojection. can try code, can find at: http://weblogs.asp.net/ricardoperes/archive/2014/03/06/custom-nhibernate-criteria-projections.aspx. let me know if helped.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -