开发者

Calling a store procedure with nHibernate

开发者 https://www.devze.com 2022-12-08 10:20 出处:网络
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 t

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号