Is this possible using QueryOver or CreateCriteria:
SELECT FooName, SUM(FooAmount)
FROM (
SELECT
(SELECT Name FROM Foo
WHERE Foo.BarId = Bar.Id) as FooName,
FooAmount
FROM Bar
) as inner_query
GROUP BY FooName
Please note that this query has been constructed for demonstration purposes. I am not interested in adding relationships between entities, rewriting the query itself etc. Also, the app is setup to take advantage of query construction using CreateCriteria - it is not possible to change it to HQL.
It is possible to construct the inner query in NHibernate as a detatched criteria. The problem is getting NHibernate to select from the inner query, instead of over an entity. Does anyone know if this is possible?