Trying to implement following queries in NHibernate QueryOver.
SQL
SELECT
SUM(GrossChargeAmount)
FROM Charges
INNER JOIN Account on Account.Chargekey = Charges.Chargekey
SELECT
SUM(GrossChargeAmount),
Account.AccountHolder
FROM Charges
INNER JOIN Account on Account.Chargekey = Charges.Chargekey
GROUP BY
Account.AccountHolder
NHibernate:
var accountAlias = null;
var baseQuery = session.QueryOver<Charges>()
.JoinAlias(c => c.Account, () => accountAlias)
.SelectList(s => s.SelectSum(c => c.GrossChargeAmount))
I have code that constructs the baseQuery. I then, depending on method parameters will want to append the GROUP BY to the baseQuery like:
baseQuery.SelectList(s => s.GroupBy(() => accountAlias.AccountHolder)
This however ends up resetting projections on my baseQuery and essentially "overwritting" the initial projections ( .SelectList(s => s.SelectSum(c => c.GrossChargeAmount)) ). At this stage an execution of the query will not have any SUM() bu just the GROUP BY.
TLDR; How do I add projections to an Nhibernate QueryOver instance?
Last, but not least I'm running on NHibernate 2.0.50727