aggregate-functions


NHibernate - QueryOver criteria appearing in Where instead in Having clause, error


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 appears in Where clause and result in error. **Error** ="*An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference*"
Conjunction conjunction = Restrictions.Conjunction();
Conjunction havingconjun = Restrictions.Conjunction();
conjunction.Add<Vendor>(p => v.Name == "Some Vendor");
havingconjun.Add(Restrictions.Gt(
Projections.Sum(Projections.Property(() => v.Payments),
Convert.ToDouble(SomeInvoice.Value)));
var reportModels =
Session.QueryOver<Vendor>(() => v)
.Where(conjunction)
.Where(havingconjun)
.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>();
Expected Result:
SELECT
V.VENDORNUMBER, V.VENDORTYPE, V.VENDORNAME, SUM(V.PAYMENTS)
FROM VENDOR V
WHERE V.NAME = "Some Vendor"
GROUP
BY V.VENDORNUMBER, V.VENDORTYPE, V.VENDORNAME
HAVING SUM(V.PAYMENTS) > somevalue
Getting Now:
SELECT
V.VENDORNUMBER, V.VENDORTYPE, V.VENDORNAME, SUM(V.PAYMENTS)
FROM VENDOR V
WHERE V.NAME = "Some Vendor" AND
SUM(V.PAYMENTS) > somevalue
GROUP
BY V.VENDORNUMBER, V.VENDORTYPE, V.VENDORNAME
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

Related Links

Creating an aggregate function fails
Necessity of declaration of function in c and cpp
Calculate window average in tableau
Complexity asymptotic relation (theta, Big O, little o, Big Omega, little omega) between functions
What are TOP_COUNT and TOP_MAXCOUNT in BigQuery?
marklogic need advise for approach to aggregate documents
multiply(num) aggregate function in postgresql
Binding the Result of an Aggregate Function to a Projected Variable
tableau aggregate data based on dimension
where clause and aggregate functions
Is there such a thing as a join() aggregate function that concatentates field values at a specific character?
Aggregation of an expression in Django query spanning multiple tables
How to aggregate / roll up percentile measures
A peer-to-peer and privacy-aware data mining/aggregation algorithm: is it possible?
Multiple aggregates in SPARQL
SAP BO XI Desktop Intelligence Aggregate Calculations

Categories

HOME
oauth-2.0
asterisk
teradata
ns2
gsm
cluster-analysis
openacc
abc
conceptual
singleton
crash
opengl-es
snmp
pdf-generation
rmarkdown
osx-yosemite
vsixmanifest
pyodbc
runtime
spring-data-solr
olap
openbsd
jpql
unreal-engine4
osclass
resharper
camunda
opendaylight
minimum
hql
popup
owncloud
taxonomy
cucumberjs
gpo
inspec
knapsack-problem
android-6.0-marshmallow
azure-table-storage
schedule
drawrect
log4net-configuration
n1ql
hippocms
yelp
delphi-xe
irr
codepen
jenkins-2
rivets.js
monaca
photoshop-script
node-java
activesupport
sharpssh
reloaddata
stripes
indoor-positioning-system
foreground
cosign-api
syslog4j
qtruby
shtml
jmh
jsondoc
fadein
google-app-engine-php
persian
traminer
cyberduck
joomla3.3
tooltwist
esb-toolkit-2.1
mergecursor
static-files
fxmlloader
unityvs
qf-test
famous-engine
sat4j
behance-api
elixir-framework
fastcgi-mono-server
html5-filesystem
mongoid4
nativequery
raddatepicker
maven-webstart-plugin
dd4t
symbian3
junction-table
screensharing
volatility
shapado
blackberry-eclipse-plugin
method-call
functional-specifications
virtual-destructor
pitch-shifting
memory-consumption

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App