Nhibernate添加过滤器进行查询

时间:2013-05-08 09:27:45

标签: c# sql hibernate sqlite nhibernate

参考: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

1 个答案:

答案 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);