views:

35

answers:

0

Hey, So I may be completely off the mark here but I'm still new to nhibernate so bare with me.

I've read this article

http://www.mattfreeman.co.uk/2009/01/nhibernate-21-trunk-entity-name-some-inheritance-and-dynamic-component/

And am looking for a way to dynamically change my mapping at runtime to bind to a different table using a one-to-many dependent on a value in my parent object.

Here are my mappings

 <bag name="Data" mutable="true" >
     <key>
       <column name="Log_Link" />
       <column name="channel" />
     </key>
   <one-to-many class="Fluent.Entities.Meters.FTIMeterChannelData, Poco" entity-name="30" />
 </bag>

and

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
  <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="Fluent.Entities.Meters.FTIMeterChannelData, Poco" table="loggerData" entity-name="30">
    <composite-id mapped="false" unsaved-value="undefined">
      <key-property name="Channel" type="System.Int32">
        <column name="channel" />
      </key-property>
      <key-property name="LogLink" type="System.Int32">
        <column name="Log_Link" />
      </key-property>
    </composite-id>
    <property name="Date" type="System.DateTime">
      <column name="hhdate" />
    </property>
  </class>

  <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="Fluent.Entities.Meters.FTIMeterChannelData, Poco" table="loggerData10" entity-name="15">
    <composite-id mapped="false" unsaved-value="undefined">
      <key-property name="Channel" type="System.Int32">
        <column name="channel" />
      </key-property>
      <key-property name="LogLink" type="System.Int32">
        <column name="Log_Link" />
      </key-property>
    </composite-id>
    <property name="ReadingType" type="System.Char">
      <column name="readingtype" />
    </property>
  </class>
</hibernate-mapping>

now as the article states I should be able to change the entity name using an interceptor

 class LoggerDataInterceptor : EmptyInterceptor
    {
        public override string GetEntityName(object entity)
        {
            return Convert.ToString("20");
        }
    }

Now the question is two fold.

Firstly I can't seem to get this interceptor to fire, despite declaring it when opening my session, and secondly am I completely barking mad and is this never going to work?