NHibernate - populate one property from a stored procedure

The following mapping file is currently available:

<?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>

Which displays the legacy database that I inherited well, but I would like to add a property called "MatchTime" that contains the output of the stored procedure:

EXEC GetMatchTime @FixtureId = :Id

where: Id is the identifier of the current Fixture.

Is this possible in the mapping file?

+3
source share
3 answers

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

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

+1

, , (Id Fixture.Id):

<property name='MatchTime' formula='(EXEC GetMatchTime Id)'/>

http://ayende.com/Blog/archive/2006/12/26/LocalizingNHibernateContextualParameters.aspx

0

@Watson

NHibernate, SQL- :

SELECT FieldA, FieldB, FieldC, ( EXEC GetMatchTime Id ) FROM Fixture_Lists

, - , .

, , .

0

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


All Articles