我有这样的模型
public class Scene
{
public virtual ICollection<Ray> Rays1 {get; set;}
public virtual ICollection<Ray> Rays2 {get; set;}
}
public class Ray
{
public virtual Scene Parent {get; set;}
}
如果我保持这种方式并将其与2个一对多关系映射,就会发生这种情况:
现在Rays1和Rays2都有5个元素,因为它们共享相同的父ID
我能想到的唯一解决方案是从Ray继承2个新类,然后使用一对多关系映射每个类。这将在数据库上创建两个单独的表,但它们具有完全相同的列。它对我来说感觉不对......
还有其他解决方案吗?
- 编辑 -
供参考,这是我的映射文件:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="PanoMeasurer.Core.Domain"
namespace="PanoMeasurer.Core.Domain">
<class name="Panorama">
<id name="OID" generator="guid.comb"/>
<property name="HeadingBase"/>
<set name="Rays1" cascade="all-delete-orphan">
<key column="PanoramaId" />
<one-to-many class="Ray"/>
</set>
<set name="Rays2" cascade="all-delete-orphan">
<key column="PanoramaId" />
<one-to-many class="Ray"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="PanoMeasurer.Core.Domain"
namespace="PanoMeasurer.Core.Domain">
<class name="Ray">
<id name="OID" generator="guid.comb"/>
<property name="Heading"/>
<property name="Elevation"/>
<many-to-one name="Owner" class="Panorama" column="PanoramaId" />
</class>
</hibernate-mapping>
答案 0 :(得分:1)
如果您选择使用单个映射,则可以将Rays1和Rays2设置为光线列表中的过滤器。
public virtual ICollection Rays1 {return Rays.Where()};