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
精彩评论