nhibernate - Counting in hibernate using Criteria without unnecessary inner joins -
i using criteria counting number of rows. consider class
class groupmembership{ public group group{get;set;} public member member{get;set;} }
i have criteria fetches distinct members each group as:
detachedcriteria.for<groupmembership>("this") .createcriteria("group", "grp") .createalias("this.communitymember", "communitymember") .setprojection(projections.projectionlist() .add(projections.groupproperty("this.group.id"),"groupid") .add(projections.countdistinct("this.communitymember.id"), "totalmembers"))
is there way can count without performing inner join communitymember.
update: adding sqls generated query
select this_.groupid y0_, count(distinct communitym2_.communitymemberid) y1_ [groupmembership] this_ inner join [communitymember] communitym2_ on this_.communitymemberid = communitym2_.communitymemberid inner join [group] grp1_ on this_.groupid = grp1_.groupid group this_.groupid
as can see can avoid inner join in sql. question whether same can done in criteria.
how about...
detachedcriteria.for<groupmembership>() .setprojection(projections.projectionlist() .add(projections.groupproperty("group")) .add(projections.countdistinct("communitymember")))
Comments
Post a Comment