NHibernate 一个表达式可以在 select 列表中指定当子查询没有用 EXISTS 引入时

NHibernate one expression can be specified in the select list when the subquery is not introduced with EXISTS

我有 class,其中包含 属性,这是其他一些 class 的列表。 我想将此 class 映射到可查询扩展名中的另一个 class。

AutoMappper.CreateMap<Department1, Department2>()
AutoMapper.CreateMap<Employee1, Employee2>()
var employee1 =_session.Query<Employee1>();
employee1.Project().To<Employee2>(); 

它给出错误 'Could not excecute query Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.' select employee1_.Id 作为 col_0_0_, employee1_.Name 作为 col_1_0_, (select Department1_.Id, Department1_.Name 来自 Department.Department Department1_) as col_2_0_ from [Employee].[Employee] Employee1_

因为相同的解决方案适用于可枚举的情况 mapper.Map(员工1); 以下是 classes.

public class Employee1
{
    public int Id {get;set;}
    public string Name {get;set;}
    public List<Department1>{get;set;}
}

public class Department2
{
    public int Id {get;set;}
    public int Name {get;set;}
}

public class Employee2
{
    public int Id {get;set;}
    public string Name {get;set;}
    public List<Department2>{get;set;}
}

public class Department1
{
    public int Id {get;set;}
    public int Name {get;set;}
}

您需要使用 NHibernate 4,它对嵌套集合的投影能力有限。