NHibernate Projections - how to design collections

There is a scenario in which I need to select only one / several columns from the object, but several children in the query. I tried with projections, but got an error in the property of the collections. This is such a normal situation, but cannot find information on designing collections - only properties.

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>();

Error returned:

System.IndexOutOfRangeException : Index was outside the bounds of the array
+5
source share
2 answers

Impossible to do in NH 3.3. https://nhibernate.jira.com/browse/NH-3176

+3
source

How about reversing a request (assuming Order has a Customer property):

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[]>();
+2
source

All Articles