每个类层次结构的nhibernate表,映射隐藏基类成员的派生类成员

时间:2011-05-26 15:22:07

标签: nhibernate nhibernate-mapping

class FooBase{...}
class FooDerived : FooBase {...}

class BaseContainer
{
    public virtual FooBase Foo {get;set;}
}

class DerivedContainer : BaseContainer
{
    public virtual new FooDerived Foo {get;set;}
}

Hibernate映射选项 选项1如下 无法在NHibernate上保持持久化,在xml中生成额外的成员声明(索引超出范围错误)

   <class name="BaseContainer" discriminator-value="0">

         <discriminator column="ContainerType" type="int" />

         <many-to-one name="Foo"
                      foreign-key="..."
                      class="FooBase"
                      column="FooId"
                      unique="true"/>

          <subclass name="DerivedContainer"  discriminator-value="1">

               <many-to-one name="Foo"
                            foreign-key="..."
                            class="FooDerived"
                            column="FooId"

                            unique="true"/>
          </subclass>

   </class>

选项2独立映射! 获取操作错误,不区分类型

   <class name="BaseContainer" discriminator-value="0">

         <discriminator column="ContainerType" type="int" />

         <many-to-one name="Foo"
                      foreign-key="..."
                      class="FooBase"
                      column="FooId"
                      unique="true"/>

   </class>

   <class name="DerivedContainer"  discriminator-value="1">

        <many-to-one name="Foo"
                     foreign-key="..."
                     class="FooDerived"
                     column="FooId"
                     unique="true"/>

  </class>

坚持,会感激任何指针,虽然我明白这可以通过每个子类的表完成很容易实现,有没有上面的方法可以通过表每个类层次结构实现

0 个答案:

没有答案