参考:nhibernate criteria for selecting from different tables
基于这个问题,我想通过示例Unit.Amount == 5过滤这个检索到的最后5个订单! (添加过滤器)我认为这可能是这样的:
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);
有人可以帮我找到正确的查询吗?
THX
答案 0 :(得分:1)
使用联接可以解决您的问题
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);