5

There is an excellent post on how to map return values for a stored procedure call here: http://elegantcode.com/2008/11/23/populating-entities-from-stored-procedures-with-nhibernate/

The mapping in this example has been done through hbm files.

I am trying to use the latest version of Nhibernate (3.2) where we can do mapping through code. I really want to find out the C# code that would create a mapping like below:

<sql-query name="GetProductsByCategoryId">
    <return class="Product">
      <return-property column="ProductID" name="Id" />
      <return-property column="ProductName" name="Name" />
      <return-property column="SupplierID" name="Supplier" />
      <return-property column="CategoryID" name="Category" />
      <return-property column="QuantityPerUnit" name="QuantityPerUnit" />
      <return-property column="UnitPrice" name="UnitPrice" />
      <return-property column="UnitsInStock" name="UnitsInStock" />
      <return-property column="UnitsOnOrder" name="UnitsOnOrder" />
      <return-property column="ReorderLevel" name="ReorderLevel" />
      <return-property column="Discontinued" name="Discontinued" />
    </return>
    exec dbo.GetProductsByCategoryId :CategoryId
</sql-query>
Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
dreamerkumar
  • 1,540
  • 1
  • 18
  • 28

1 Answers1

1

To be honest I never tried it, by you should take a look to the extension method AddNamedQuery(..): you call it from you Configuration instance (NHibernate.Cfg namespace)).

Some examples on the NHibernate test project.

By the way, you can mix the new 3.2 mapping-by-code and xml one. Start to look at this question;

Community
  • 1
  • 1
Michele Lepri
  • 440
  • 3
  • 9
  • 1
    Thanks Michele, I know about the mixing up part. In fact I used the classic hbm file mapping just like above to make it work through 3.2. But the AddNamedQuery(..) is really what I am looking for to do mapping by code. – dreamerkumar Dec 05 '11 at 21:30