nhibernate动态绑定一个类
我读过 这篇文章,并且正在寻找一种在运行时动态更改映射的方法,以使用依赖于父对象中的值的一对多绑定到不同的表。
这是我的映射
<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");
}
}
现在问题有两个。
首先,尽管在打开会话时声明了该拦截器,但我似乎无法启动该拦截器,其次,我是否完全发疯了,这永远不会起作用吗?
I've read this article, 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以评论第一个问题。打开会话时是否传递拦截器?
I can comment on the first question. Are you passing the interceptor when you open the session?