Problem with NHibernate stored procedure

It's hard for me to try to get my stored procedure to work with NHibernate. The data returned from the SP does not match 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}

on line 80

Line 78:             config.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NHibernate.config"));            
Line 79: 
Line 80:             g_sessionFactory = config.BuildSessionFactory();       

When I debug NHibernate code, it seems SomeClass is not added to the persister dictionary, because there is no class mapping in hbm.xml (only sql-query). And later in the CheckNamedQueries function, he will not be able to find a persistor for SomeClass.

I checked all the obvious things (for example, I will make hbm as an embedded resource), and my code is not much different from other samples that I found on the Internet, but for some reason I just can't get it to work. Any idea how I can solve this problem?

+3

Source: https://habr.com/ru/post/1740095/


All Articles