Correct NHibernate Mapping For Stored Procedure?

后端 未结 1 1161
傲寒
傲寒 2021-01-25 11:59

UPDATE: This is now resolved, see answer below.


I am having a bit of trouble trying to work out the correct way to write an NHibernate Mappi

相关标签:
1条回答
  • 2021-01-25 12:40

    RESOLVED: I have now resolved this issue. First of all there was the issue of the ID property being set to "name=Id" instead of "name=Month". Secondly, I had to wrap the exec command in a CDATA and also put a comma seperator between the parameters. The full working mapping file is below for future reference to anyone experiencing a similar problem.

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                       assembly="TestApp.DataAccess"
                       namespace="TestApp.DataAccess.Models">
    
      <class name="MonthlyInstructionCount" lazy="true">
        <id name="Month">
          <generator class="native" />
        </id>
    
        <property name="MapRequests" />
        <property name="Instructions" />
        <property name="DrainsLookSee" />
        <property name="DrainsFullCctv" />
        <property name="Soils" />
        <property name="Roots"/>
        <property name="Arb" />
    
        <loader query-ref="MI_MonthlyInstructionCount"/>
      </class>
    
      <sql-query name="MI_MonthlyInstructionCount">
        <return class="MonthlyInstructionCount">
          <return-property name="Month" column="Month" />
          <return-property name="MapRequests" column="MapRequests" />
          <return-property name="Instructions" column="Instructions" />
          <return-property name="DrainsLookSee" column="DrainsLookSee" />
          <return-property name="DrainsFullCctv" column="DrainsFullCctv" />
          <return-property name="Soils" column="Soils" />
          <return-property name="Roots" column="Roots" />
          <return-property name="Arb" column="Arb" />
        </return>
        <![CDATA[ 
        exec MI_MonthlyInstructionCount :StartDate, :NumberOfMonths
        ]]>
      </sql-query>
    
    </hibernate-mapping>
    

    Cheers!

    0 讨论(0)
提交回复
热议问题