3

我已经阅读了这篇文章,并且正在寻找一种方法来在运行时动态更改我的映射,以使用依赖于父对象中的值的一对多绑定到不同的表。

这是我的映射

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

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

现在正如文章所述,我应该能够使用拦截器更改实体名称

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

现在的问题是双重的。

首先,尽管在打开我的会话时声明了它,但我似乎无法启动这个拦截器,其次我完全疯了,这永远不会奏效吗?

4

1 回答 1

0

我可以评论第一个问题。打开会话时是否通过拦截器?

config.SetInterceptor(new yourInteceptor());

.........

if (config.Interceptor != null)
{
     session = factory.OpenSession(config.Interceptor);
}
     else
{    
     session = factory.OpenSession();
}
于 2011-03-25T11:45:58.887 回答