我很难让我的存储过程与 NHibernate 一起工作。从 SP 返回的数据不对应任何数据库表。
这是我的映射文件:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainModel" namespace="DomainModel.Entities">
<sql-query name="DoSomething">
<return class="SomeClass">
<return-property name="ID" column="ID"/>
</return>
exec [dbo].[sp_doSomething]
</sql-query>
</hibernate-mapping>
这是我的域类:
namespace DomainModel.Entities
{
public class SomeClass
{
public SomeClass()
{
}
public virtual Guid ID
{
get;
set;
}
}
}
当我运行代码时,它失败了
Exception Details: NHibernate.HibernateException: Errors in named queries: {DoSomething}
在第 80 行
Line 78: config.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NHibernate.config"));
Line 79:
Line 80: g_sessionFactory = config.BuildSessionFactory();
当我调试 NHibernate 代码时,似乎 SomeClass 没有添加到持久化字典中,因为在 hbm.xml 中没有定义类映射(只有 sql-query)。后来在 CheckNamedQueries 函数中,它无法找到 SomeClass 的持久化器。
我已经检查了所有明显的东西(例如,将 hbm 作为嵌入式资源),我的代码与我在网上找到的其他示例并没有太大的不同,但不知何故我就是无法让它工作。知道如何解决这个问题吗?