【问题标题】:Calling a store procedure with nHibernate使用 nHibernate 调用存储过程
【发布时间】:2009-10-11 21:38:05
【问题描述】:

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

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

【问题讨论】:

    标签: .net nhibernate stored-procedures


    【解决方案1】:

    文档建议为存储过程映射命名查询:

    <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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      相关资源
      最近更新 更多