NHibernate one expression can be specified in the

2019-07-20 09:35发布

问题:

I am having class which contain property which is list of some other class. I want to map this class to another class in queryable extension.

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

It give error '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 as col_0_0_, employee1_.Name as col_1_0_, (select Department1_.Id, Department1_.Name from Department.Department Department1_) as col_2_0_ from [Emplolyee].[Employee] Employee1_

As same solution works on Enumerable case mapper.Map(employee1); Below are the 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;}
}

回答1:

You need to use NHibernate 4, which has some limited ability to project nested collections.