NHibernate存储过程问题
我很难让我的存储过程与 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 没有添加到持久器字典中,因为没有类映射(仅 sql-query)在 hbm.xml 中定义。后来在 CheckNamedQueries 函数中,它无法找到 SomeClass 的持久化器。
我已经检查了所有明显的事情(例如,将 hbm 作为嵌入式资源),并且我的代码与我在网络上找到的其他示例没有太大不同,但不知何故我无法让它工作。知道如何解决这个问题吗?
I'm having a hard time trying to get my stored procedure works with NHibernate. The data returned from the SP does not correspond to any database table.
This is my mapping file:
<?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>
Here is my domain class:
namespace DomainModel.Entities
{
public class SomeClass
{
public SomeClass()
{
}
public virtual Guid ID
{
get;
set;
}
}
}
When I run the code, it fails with
Exception Details: NHibernate.HibernateException: Errors in named queries: {DoSomething}
at line 80
Line 78: config.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NHibernate.config"));
Line 79:
Line 80: g_sessionFactory = config.BuildSessionFactory();
When I debug into NHibernate code, it seems that SomeClass is not added to the persister dictionary because there isn't a class mapping (only sql-query) defined in hbm.xml. And later on in CheckNamedQueries function, it is not able to find the persistor for SomeClass.
I've checked all the obvious things (e.g. make hbm as an embedded resource) and my code isn't too much different from other samples I found on the web, but somehow I just can't get it working. Any idea how I can resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么,SomeClass 的类映射在哪里?
您仍然需要绘制它。阅读 http://nhibernate.info/doc/nh/en/index .html#querysql-load。
Well, where is your class mapping for SomeClass?
You still need to map it. Read http://nhibernate.info/doc/nh/en/index.html#querysql-load.
查看使用带有
subselect
块的类映射。我在 Java 文档中找到了这个,但也许它也适用于 .Net。http://docs.jboss.org/hibernate/ core/3.3/reference/en/html/mapping.html(向下滚动到第 5.1.3 节)
Look at using a class mapping with a
subselect
block. I found this in the Java documentation but maybe it will work for .Net too.http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html (scroll down to section 5.1.3)