Is there anyway to do a join to a select statement using NHibernate (QueryOver if possible)?
Here is the SQL I'm hoping to generate
SELECT r.MaxReading, r.MeterId, m.PreviousHours
FROM
Meters m
LEFT JOIN
(SELECT Max(mr.ReadingHours) as MaxReading, mr.AssetMeterId
FROM MeterReadings mr
WHERE mr.MeterId IN(1,2)
GROUP BY mr.MeterId) r
ON m.Id=r.MeterId
I did find this post, but it looks like the answer was to build a different query. Which makes me think this may not be possible.
I already figured out how to build the subquery piece, so any answer can just use a simple query in it's place as an example. Thanks!
As far as I know, it's impossible to join on a subquery in NHibernate since all joins must come from relations in your object model.