NHibernate预测 - 如何预测集合

时间:2012-05-12 12:37:57

标签: nhibernate

有一个场景我只需从实体中选择一个/几个列,但在查询中只有多个子项。 我一直在尝试使用投影,但在collections属性上遇到错误。这是一种正常情况,但无法找到有关投影集合的信息 - 仅限属性。

Customer customerAlias = null;
Order orderAlias = null;
 var list = _session.QueryOver<Customer>(() => customerAlias)
                    .JoinAlias(x => x.Orders, () => orderAlias, JoinType.LeftOuterJoin)
                    .Select(
                       Projections.Property(() => customerAlias.Name),
                       Projections.Property(() => customerAlias.Orders))//this is the issue
                   .List<object>();

返回的错误是:

System.IndexOutOfRangeException : Index was outside the bounds of the array

2 个答案:

答案 0 :(得分:3)

无法在NH 3.3中完成。 https://nhibernate.jira.com/browse/NH-3176

答案 1 :(得分:2)

如何反转查询(假设Order具有Customer属性):

var list = _session.QueryOver<Order>()
                .Select(
                   Projections.Property(o => o.Customer.Name),
                   Projections.Property(o => o.OrderProperty1),
                   Projections.Property(o => o.OrderProperty2)) // etc..
               .List<object[]>();