本文介绍了NHibernate投影-如何投影集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种情况,我只需要从实体中选择单个/很少的列,而在查询中选择多个子代.我一直在尝试投影,但是在collections属性上遇到错误.这是一种正常情况,但无法找到有关投影集合的信息-仅能找到属性.

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

返回的错误是:

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

推荐答案

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

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

这篇关于NHibernate投影-如何投影集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 04:21