嘗試在NHibernate QueryOver中實現以下查詢。動態添加投影到NHibernate查詢
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))
我有一個構建baseQuery代碼。我然後根據方法的參數將要追加GROUP BY到像baseQuery:
baseQuery.SelectList(s => s.GroupBy(() => accountAlias.AccountHolder)
然而,這結束了復位我baseQuery預測,基本上「overwritting」的初步預測(.SelectList(S => s.SelectSum(c => c.GrossChargeAmount)))。在這個階段,查詢的執行不會有任何SUM()bu只是GROUP BY。
TLDR;如何將投影添加到Nhibernate QueryOver實例?
最後,但並非最不重要,我NHibernate的運行2.0.50727
有沒有例如NHibernate 2.0.50727 –