Calling a storage procedure using nHibernate

How do you call a stored procedure using nHibernate?

In particular, there are two cases when I use repository procedures: return a scalar value and return a set of results associated with entities.

+3
source share
1 answer

The documentation suggests the following for mapping a named query to 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 can be called using:

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

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

+4

Source: https://habr.com/ru/post/1719835/


All Articles