Reputation: 1834
using nHibernate QueryOver I want to select a series of values that include an aggregate expression. So the sql might be:
SELECT SUM(Total / (TaxRate + 1)) Totals FROM Contract Group By CustomerId
I can't see where (or if) this is supported. It seems odd that I can write where clauses as expressions but not define columns in the select as expressions.
Upvotes: 2
Views: 1021
Reputation: 15579
Since I dont have your code I cant verify any of this but you can try this:
var dividePropertyProjection = Projections.SqlProjection(
"SUM(Total/TaxRate+1) as Totals", new string[] {"Totals"}, new IType[] {NHibernateUtil.Decimal}); //Assuming the sum is decimal, you can change it
var list= Session.QueryOver<Contract>().Select(Projections.Group<Contract>(x=>x.CustomerId),dividePropertyProjection).List();
Not sure what list will return, I am guessing it should return CustomerId, Sum
combination.
Hope that helps
Upvotes: 1