Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Projections - how to project collections

Tags:

nhibernate

Have a scenario where I need to only select a single/few columns from an entity, but multiple children in a query. I have been trying with projections but getting an error on the collections property. This is such a normal situation, yet cannot find info on projecting 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 is:

System.IndexOutOfRangeException : Index was outside the bounds of the array
like image 369
Samuel Goldenbaum Avatar asked May 12 '12 12:05

Samuel Goldenbaum


1 Answers

Cannot be done in NH 3.3. https://nhibernate.jira.com/browse/NH-3176

like image 175
Samuel Goldenbaum Avatar answered Sep 26 '22 02:09

Samuel Goldenbaum