I have a problem in QueryOver where using Group by and have some criteria in where clause. Want to move some criteria with SUM() values in Having clause but every time it ap
Well as many people could not find the solution of this in NHibernate, then I used some simple trick to achieve my results which I could say a solution to this problem until NHibernate fix it.
After getting the removing criteria from having and running simple queryover it looked like this.
var reportModels =
Session.QueryOver<Vendor>(() => v)
.Where(conjunction)
.SelectList(list => list
.SelectGroup(() => v.Number).WithAlias(() => vModel.VendorNumber)
.SelectGroup(() => vtypeCode.Code).WithAlias(() => vModel.VendorType)
.SelectGroup(() => v.Name).WithAlias(() => vModel.VendorName))
.TransformUsing(Transformers.AliasToBean<VendorAnalysisReportModel>())
.List<VendorAnalysisReportModel>();
var vlst2 =
(from vendrs in reportModels orderby vendrs.VendorName ascending select vendrs)
.ToList<VendorAnalysisReportModel>().AsQueryable();
and then you can put as many where clause as you want on any field.
vlst2 = vlst2.Where(p => p.OutstandingComm > Convert.ToDecimal(toDateComAmount.Value));
vlst2 = vlst2.Where(p => p.ToDateOrders < Convert.ToDecimal(toDateOrdAmount.Value));
My problem was solved and the complex report is running successfully and we are following the same this in other queries as well.
QF