NHibernate存储过程问题

发布于 2024-08-27 18:33:43 字数 1379 浏览 6 评论 0原文

我很难让我的存储过程与 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄风 2024-09-03 18:33:43

那么,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.

饮湿 2024-09-03 18:33:43

查看使用带有 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文