Reputation: 5649
Reference: nhibernate criteria for selecting from different tables
Based on this question I want to filter this retrieved last 5 orders by at example Unit.Amount == 5! (add filter) I think it's possible with something like this:
var query = m_hibernateSession.QueryOver<Model.Order>()
// .Where(x => x.Units[].Amount == 5) ... // which Unit to select in this list?
.OrderBy(x => x.PONumber).Desc.Take(5);
Could someone please help me to find the right query?
Thx
Upvotes: 0
Views: 914
Reputation: 9271
Using a join should solve your problem
Order orderAlias = null;
Unit unitsAlias = null;
var query = session.QueryOver<Order>(() => orderAlias)
.JoinAlias(() => orderAlias.Units, () => unitsAlias, JoinType.InnerJoin)
.Where(() => unitsAlias.Amount == 5)
.OrderBy(x => x.PONumber).Desc.Take(5);
Upvotes: 1