title: Correct NHibernate Mapping For Stored Procedure?
body: <hr>
  
  <p><strong>UPDATE: This is now resolved, see answer below.</strong></p>
  
  <hr>
  
  <p>I am having a bit of trouble trying to work out the correct way to write an NHibernate Mapping File (.hbm.xml) for a MSSQL Stored Procedure.</p>
  
  <p>The Stored Procedure accepts two parameters and returns a single row result set containing several columns which have integer values.</p>
  
  <p>My mapping file is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                     assembly="TestApp.DataAccess"
                     namespace="TestApp.DataAccess.Models"&gt;
  
    &lt;class name="MonthlyInstructionCount" lazy="true"&gt;
      &lt;id name="Id" column="Month"&gt;
        &lt;generator class="native" /&gt;
      &lt;/id&gt;
  
      &lt;property name="Month" /&gt;
      &lt;property name="MapRequests" /&gt;
      &lt;property name="Instructions" /&gt;
      &lt;property name="DrainsLookSee" /&gt;
      &lt;property name="DrainsFullCctv" /&gt;
      &lt;property name="Soils" /&gt;
      &lt;property name="Roots"/&gt;
      &lt;property name="Arb" /&gt;
  
      &lt;loader query-ref="MI_MonthlyInstructionCount"/&gt;
    &lt;/class&gt;
  
    &lt;sql-query name="MI_MonthlyInstructionCount"&gt;
      &lt;return class ="MonthlyInstructionCount"&gt;
        &lt;return-property name="Month" column="Month" /&gt;
        &lt;return-property name="MapRequests" column="MapRequests" /&gt;
        &lt;return-property name="Instructions" column="Instructions" /&gt;
        &lt;return-property name="DrainsLookSee" column="DrainsLookSee" /&gt;
        &lt;return-property name="DrainsFullCctv" column="DrainsFullCctv" /&gt;
        &lt;return-property name="Soils" column="Soils" /&gt;
        &lt;return-property name="Roots" column="Roots" /&gt;
        &lt;return-property name="Arb" column="Arb" /&gt;
      &lt;/return&gt;
      exec dbo.MI_MonthlyInstructionCount :StartDate :NumberOfMonths
    &lt;/sql-query&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>I have also tried the following, as suggested by someone on a forum for a similar problem another person was having relating to Stored Procedures...</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                     assembly="TestApp.DataAccess"
                     namespace="TestApp.DataAccess.Models"&gt;
  
    &lt;sql-query name="MI_MonthlyInstructionCount"&gt;
      &lt;return class ="MonthlyInstructionCount" /&gt;
      exec dbo.MI_MonthlyInstructionCount :StartDate :NumberOfMonths
    &lt;/sql-query&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Neither of which seem to work... I just get the following error:</p>
  
  <blockquote>
    <p>The type initializer for
    'TestApp.DataAccess.Sql.NHibernateHelper'
    threw an exception.</p>
    
    <p>{"Errors in named queries:
    {MI_MonthlyInstructionCount}"}</p>
  </blockquote>
  
  <p>I can't see it being the Stored Procedure (though the error would suggest it is...) as it seems to run successfully in MSSQL Server Manager.</p>
  
  <p>Any help is much appreciated! Cheers!</p>