如何为存储过程编写映射
这里有一篇关于如何映射存储过程调用的返回值的优秀文章: http://elegantcode.com/2008/ 11/23/populate-entities-from-stored-procedures-with-nhibernate/
此示例中的映射是通过 hbm 文件完成的。
我正在尝试使用最新版本的 Nhibernate (3.2),我们可以通过代码进行映射。我真的很想找到可以创建如下映射的 C# 代码:
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,我从未尝试过,您应该看看扩展方法
AddNamedQuery(..)
:您从Configuration
实例(NHibernate .Cfg
命名空间))。一些示例关于 NHibernate 测试项目。
顺便说一句,您可以混合使用新的 3.2 代码映射和 xml 映射。
开始看这个问题;
To be honest I never tried it, by you should take a look to the extension method
AddNamedQuery(..)
: you call it from youConfiguration
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;