I would like to write the following SQl in NHibernate – Detached Criteria if possible.
select * from parent
INNER JOIN child on parent.id=child.parentid
INNER JOIN
(select ChildID, MAX(ChildDate) MaxChildDate from child group by ChildID) max
ON child.childid, child.ChildDate=max.MaxChildDate
This gives me the latest child in every paret.
I can write the sub-query in Critera but cannot perform the double link of ChildID and MaxDate.
Thanks, the join wasn’t quite as simple as the example and there were a lot of tables being used – fine if done in a SQL set based setup but there would have been a ridiculous amount of data coming back to filter it in linq.
Unfortunately speed had to win over design so I created a view with the complex join in and used that as a table for a dictionary on the primary domain object. Thanks for all your help though.
Cheers
Stu