I have following table model:
I want following SQL command as nhibernate c
If you want the last five orders I would approach the problem with a slightly different query
Select *
From order o join Units U on O.OID = U.OID
Order by O.PONumber limit 5
in nhibernate would be something like that (not tested)
Order orderAlias = null;
Unit unitAlias = null;
var query = session.QueryOver(() => orderAlias)
.JoinAlias(() => orderAlias.Units, () => unitAlias, JoinType.InnerJoin)
//.TransformUsing(Transformers.DistinctRootEntity) if you have duplicates
.OrderBy(x => x.PONumber).Desc.Take(5);
UPDATE
You could also just load Order
entity. NHibernate will load automatically all units rows, based on your mapping info (lazy/eager loading or joins).
var query = session.QueryOver().OrderBy(x => x.PONumber).Desc.Take(5);