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>
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With