I would like to get this SQL from NHibernate:
SELECT SUM(color_pages) * SUM(total_pages)
FROM connector_log_entry
GROUP BY department_name
Arithmetic operators can be used in criteria queries via the VarArgsSQLFunction
SQL function. In your particular case, this would look something like:
Session.QueryOver()
.SelectList(list =>
list.SelectGroup(m => m.DepartmentName)
.WithAlias(() => dto.Department)
.Select(Projections.SqlFunction(
new VarArgsSQLFunction("(", "*", ")"),
NHibernateUtil.Int32,
Projections.Sum(m => m.TotalPages),
Projections.Sum(m => m.ColorPages)))
.WithAlias(() => dto.TotalColorPercentage))
.TransformUsing(Transformers.AliasToBean());
This technique injects strings directly into the generated SQL, so you'll need to make sure the underlying database supports the operators you use.