c# - NHibernate 可以在子查询不引入EXISTS时在select list中指定一个表达式

标签 c# asp.net asp.net-mvc nhibernate automapper

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

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 as col_0_0_, employee1_.Name as col_1_0_, (select Department1_.Id, Department1_.Name from Department.Department Department1_) 作为 col_2_0_ from [Employee].[Employee] Employee1_

因为相同的解决方案适用于可枚举的情况 mapper.Map(employee1); 以下是类。

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,它在投影嵌套集合方面的能力有限。

关于c# - NHibernate 可以在子查询不引入EXISTS时在select list中指定一个表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28021423/

相关文章:

c# - 通用参数。如何传递给构造函数然后添加到列表?

c# - 从 ASP.Net 打印 PDF,无需预览

asp.net-mvc - 在 Azure 中使用 DataAnnotations 进行验证显示错误的文本

asp.net-mvc - MVC 3 Ajax.ActionLink 不起作用

asp.net-mvc - 使用强类型对象保持 Controller 和 View 分离

c# - 应用程序在 Linux 上运行时连接到 MSSQL Server 2017 超时

c# - 带有模板的 MVC 3 html 助手

c# - 使用 NewtonSoft JSON.net 将 JSON 解析为 C# 对象

c# - 在 asp.net web api 应用程序中找不到 Json 类型

asp.net - 如何将 devexpress 添加到 Visual Studio 2012