【发布时间】:2014-10-22 16:57:43
【问题描述】:
我有一个类和一个简单的存储过程,如下面的代码所示。问题是我想使用 NHibernate 来执行存储过程并返回一个 DTO / 实体(映射没有唯一键)。有人知道吗?请帮我。谢谢
public class Dto
{
public virtual int DeptId { get; set; }
public virtual int EmpId { get; set; }
public virtual String Name { get; set; }
}
// mapping without id => because the stored procedure returns
// results that do not have unique column
public class DtoMap : ClassMapping<Dto>
{
public DtoMap()
{
Property(x => x.EmpId, m => m.Column("emp_id")); // if emp_id is PK and I use Id here, it is ok. But in my case it is impossible
Property(x => x.DeptId);
Property(x => x.Name, m => m.Column("name"));
}
}
简单代码用于使用正确配置的 NHibernate 进行查询
var list = session.GetNamedQuery("GetAll").List<Dto>();
存储过程
CREATE PROC [dbo].[GetAll]
AS
SELECT
employeeid as emp_id, deptid, name
FROM
Employee; -- the query can not change
【问题讨论】:
标签: nhibernate stored-procedures dto