Hi all,
I have a problem with NHibernate that I don't seem to be able to find a simple way around.
I have the following database:
Game: ID, Score, Match_ID
Match: ID
A match consists of 3 games.
I want to find out what the maximum Match score is, so the following SQL would do the trick:
select max(a.total) from
(select Match.ID, sum(Game.Score) as total
from Game inner join Match
on Game.Match_ID = Match.ID
group by Match.ID) a
In NHibernate, this appears to be a bit trickier. Apparently, HQL does not allow subqueries in the from clause, so I can't really use this.
I'm pretty sure that it can be done with ICriteria, but I've only just started using NH so I can't seem to figure it out. I've basically got to the following:
Session.CreateCriteria<Game>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.GroupProperty("Match"))
.Add(Projections.Sum("Score"))).List();
After that I've played around with various assortments of DetachedCriteria, but just seem to be going round in circles.