【发布时间】:2012-04-25 16:13:25
【问题描述】:
我认为主要问题是子类删除了与基本映射集合相关的所有约束。
使用每个具体类策略的表,我发现父集合不与子类关联也在另一个(可能相关)问题中,Basetypes 和 ChildTypes 之间的关联也没有创建.
我有一个类似这样的架构:
public class Parent{
public virtual Int64 Id{get; set;}
public virtual IList<Foo> foos{get; set;}
public virtual IList<ParentType> _pts{get; set;}
}
public class child: Parent{
public virtual int chilInt{get; set;}
}
public class BaseType{
public virtual Int64 Id{get; set;}
public virtual Parent ParentReference{get; set;}
}
public class ChildType: BaseType{
public virtual string childBacon{get; set;}
}
映射文件
<class name="Parent" abstract="true">
<id name="Id" type="Int64" column="Id" unsaved-value="0">
<generator class="native"/>
</id>
<set name="foos" inverse="false" >
<key column="Id"/>
<one-to-many class="Foo" />
</set>
<set name="pts" inverse="false" >
<key column="Id"/>
<one-to-many class="ParentType" />
</set>
</class>
<union-subclass name="Child" table="Child" extends="Parent">
<property name="childInt" type="int" />
</union-subclass>
<class name="ParentType" abstract="true">
<id name="Id" type="Int64" column="Id" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="ParentReference" class="Parent"/>
</class>
<union-subclass name="ChildType" table="ChildType" extends="ParentType">
<property name="childBacon" type="string" />
</union-subclass>
子表与foo表没有任何关系的结果。
【问题讨论】:
-
您能说得更具体些吗?目前尚不清楚问题是什么。 (另外还有明显的问题,比如使用 'ref' 作为名称。你的代码不会编译,除非你不使用 C# :))
-
谢谢,我做了一些更改和更正,希望这能更好地解释我的疑问,任何更多建议将不胜感激:)
标签: nhibernate inheritance nhibernate-mapping