Using NHibernate with a stored procedure OR

I have a mapping in NHibernate that works like this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="BizEntities"
    namespace="BizEntities"
    default-lazy="false">
  <class name="SubscriberQueueItem" table="SubscriberQueueItem">
    <id name="SubscriberQueueItemId" column="Id" type="int" unsaved-value="0">
      <generator class="identity" />
    </id>
    <property name="DateCreated" column="DateCreated"  type="DateTime" />
    <property name="CMIId" column="CMIId" type="int" />
    <property name="DateProcessed" column="DateProcessed"  type="DateTime" />
    <property name="EventStatus" column="EventStatusId" type="QueueStatusTypeValues, BizEntities" />
    <many-to-one  name="Subscription"  class="Subscription" column="SubscriptionId" />
    <property name="ErrorDescription" column="ErrorDescription" type="string" />

  </class>
</hibernate-mapping>

and it is retrieved using simple table queries.

Is it also possible to map this class to a stored procedure? I have a written procedure that discards a particular subsection of data that is difficult to write to the NHibernate request, but is easily written as a stored procedure.

Is it possible to simply add the stored procedure mapping as an answer here and get an object with a direct mapping or stored procedure based on my NHibernate request type or add a stored procedure mapping for my hbm that means I can only restore based on this stored procedure?

+3
source
2

NHibernate, :)

" " hibernate, :

<sql-query name="spMyProcedure">
    <!-- return type must be an NHibernate mapped entity -->
    <return alias="SubscriberQueueItem" type="BizEntities.SubscriberQueueItem, BizEntities" />

    exec spMyProcedure @Param1=:Param1, @Param2=:Param2
</sql-query>

, .

sp, :

var query = session.GetNamedQuery("spMyProcedure");

query.SetParameter("Param1", "hello");
query.SetParameter("Param2", "byebye");

SubscriberQueueItem result = query.UniqueResult<SubscriberQueueItem>();
+6

All Articles