5

有一种情况,我只需要从一个实体中选择一个/几列,但在一个查询中选择多个子级。我一直在尝试预测,但在 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
4

2 回答 2

3

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

于 2012-06-09T08:21:58.430 回答
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[]>();
于 2012-05-20T13:20:11.657 回答