尝试在 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
休眠:
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 上的投影,并基本上“覆盖”初始投影( .SelectList(s => s.SelectSum(c => c.GrossChargeAmount)) )。在这个阶段,查询的执行不会有任何 SUM() 只是 GROUP BY。
TLDR;如何将投影添加到 Nhibernate QueryOver 实例?
最后,但并非最不重要的是,我在 NHibernate 2.0.50727 上运行