NHibernate-从存储过程填充单个属性 [英] NHibernate - Populate a single property from a stored procedure

查看:73
本文介绍了NHibernate-从存储过程填充单个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前具有以下映射文件:

Currently have the following mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
    namespace="NHibernateHelpers"
    assembly="App_Code.NHibernateHelpers">
  <class name="NHibernateHelpers.Fixture, App_Code" table="Fixture_Lists">
    <id name="Id" column="UniqRefNo">
      <generator class="guid" />
    </id>
    <property name="Date" column="FixDate"/>
    <property name="HomeTeamId" column="HomeId"/>
    <property name="HomeTeamName" column="Home_Team"/>
    <property name="AwayTeamId" column="AwayId"/>
    <property name="AwayTeamName" column="Away_Team"/>
    <property name="Kickoff" column="Kickoff"/>
    <bag name="Goals">
      <key column="FixID" />
      <one-to-many class="NHibernateHelpers.Goal, App_Code"/>
    </bag>
    <bag name="Bookings">
      <key column="FixID" />
      <one-to-many class="NHibernateHelpers.Booking, App_Code"/>
    </bag>
    <many-to-one name="HomeTeam" class="NHibernateHelpers.Team" column="HomeId" />
    <many-to-one name="AwayTeam" class="NHibernateHelpers.Team" column="AwayId" />
    <many-to-one name="Division" class="NHibernateHelpers.Division" column="Div_Comp" />
    <property name="HomeFullTimeScoreCode" column="Home_FT_Score"/>
    <property name="AwayFullTimeScoreCode" column="Away_FT_Score"/>
  </class>
</hibernate-mapping>

这很好地映射到了我继承的旧数据库,但是我想添加一个名为"MatchTime"的属性,其中包含存储过程的输出:

Which maps nicely to the legacy database I have inherited, but I would like to add a property named "MatchTime" that contains the output of the stored procedure:

EXEC GetMatchTime @FixtureId = :Id

其中:Id是当前灯具对象的ID.

where :Id is the Id of the current Fixture object.

在映射文件中可以吗?

推荐答案

有点笨拙-但是不将sp转换为函数,而是创建新函数并将它们用作现有sp的包装器呢?您可以将Id添加到函数中,然后将其传递给存储过程,获取执行sp的结果,然后将其传递回去.

Little kludgy -- but what about not converting the sp to functions, but creating new functions and using them as wrappers around the existing sp? You can add the Id to the function, and have it pass it to the stored procedure, grab the results of executing the sp, and pass them back.

http://sqlblog.com/blogs/denis_gobo /archive/2008/05/08/6703.aspx

这篇关于NHibernate-从存储过程填充单个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆