nhibernate - Projections with Restrictions.Discjunction -


projections restrictions.discjunction() or restrictions.or() produce clause instead of having clause. result in error (the clause cannot refer aggregate expressions).

example:

.createcriteria(typeof(salesorderline), "sol") .createcriteria("deliveryorderlines", "dol", jointype.leftouterjoin) .setprojection(     projections.groupproperty("sol.key").as("salesorderlineid"),     projections.groupproperty("sol.item"),     projections.groupproperty("sol.description"),     projections.groupproperty("sol.unitprice"),     projections.groupproperty("sol.quantity"),     projections.groupproperty("sol.discountpercentage"),     projections.groupproperty("sol.salesorder")) .add(restrictions.or(     restrictions.isnull(projections.sum("dol.quantity")),     restrictions.gtproperty("sol.quantity", projections.sum("dol.quantity")))),  .list(); 

sql result:

select this_.salesorderlineid y0_, this_.item y1_, this_.description y2_, this_.unitprice y3_, this_.quantity y4_, this_.discountpercentage y5_, this_.salesorderid y6_ salesorderline this_ left outer join deliveryorderline dol1_ on this_.salesorderlineid=dol1_.salesorderlineid  (sum(dol1_.quantity) null or this_.quantity > sum(dol1_.quantity)) group this_.salesorderlineid, this_.item, this_.description, this_.unitprice, this_.quantity, this_.discountpercentage, this_.salesorderid 

am doing wrong ? or bug in nhibernate 3.1 ?

thanks in advance :).

last time checked having clause isn't supported criteria api. you'll need use hql, support having.

to use criteria api you'll have modify query this:

select this_.salesorderlineid y0_, this_.item y1_, this_.description y2_, this_.unitprice y3_, this_.quantity y4_, this_.discountpercentage y5_, this_.salesorderid y6_ salesorderline this_ left outer join deliveryorderline dol1_ on this_.salesorderlineid=dol1_.salesorderlineid  (select sum(quantity) deliveryorderline) null or (select sum(quantity) > salesorderline ) > (select sum(quantity) deliveryorderline) group this_.salesorderlineid, this_.item, this_.description, this_.unitprice, this_.quantity, this_.discountpercentage, this_.salesorderid 

the solution i've given have performance hit because of multiple sum calculations, it'll job done.

you try this, i'm not sure if it'll run correctly:

select this_.salesorderlineid y0_, this_.item y1_, this_.description y2_, this_.unitprice y3_, this_.quantity y4_, this_.discountpercentage y5_, this_.salesorderid y6_, sum(dol1_quantity) sum1, sum(this_.quantity) sum2 salesorderline this_ left outer join deliveryorderline dol1_ on this_.salesorderlineid=dol1_.salesorderlineid  sum1 null or sum1 > sum2 group this_.salesorderlineid, this_.item, this_.description, this_.unitprice, this_.quantity, this_.discountpercentage, this_.salesorderid 

hope helped!


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -