使用nHibernate调用存储过程(Calling a store procedure with nHibernate)

编程入门 行业动态 更新时间:2024-10-26 00:19:37
使用nHibernate调用存储过程(Calling a store procedure with nHibernate)

你如何用nHibernate调用存储过程?

具体来说,有两种情况我使用存储过程:返回标量值并返回映射到实体的一组结果。

How do you call a stored procedure with nHibernate?

Specifically there are two cases where I am using store procedures: to return a scalar value and to return a set of results mapped to entities.

最满意答案

该文档建议使用以下方法映射存储过程的命名查询:

<sql-query name="selectAllEmployments_SP"> <return alias="emp" class="Employment"> <return-property name="employee" column="EMPLOYEE"/> <return-property name="employer" column="EMPLOYER"/> exec selectAllEmployments //stored procedure call here </sql-query>

这可以通过使用:

IQuery q = sess.GetNamedQuery("selectAllEmployments_SP");

这将在NHibernate 1.2.0文档的13.2.2节(映射存储过程)和9.3.2(查询命名查询)中讨论。 https://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querysql.html#sp_query

The documentation suggests the following for mapping a named query for a stored procedure:

<sql-query name="selectAllEmployments_SP"> <return alias="emp" class="Employment"> <return-property name="employee" column="EMPLOYEE"/> <return-property name="employer" column="EMPLOYER"/> exec selectAllEmployments //stored procedure call here </sql-query>

This could be called by using :

IQuery q = sess.GetNamedQuery("selectAllEmployments_SP");

This is discussed in section 13.2.2 (mapping stored procedure) and 9.3.2 (querying named query) of the NHibernate 1.2.0 documentation. https://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querysql.html#sp_query

更多推荐

nHibernate,过程,存储,return,电脑培训,计算机培训,IT培训"/> <meta name="descr

本文发布于:2023-08-04 21:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1422013.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:存储过程   nHibernate   Calling   procedure   store

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!