【发布时间】:2015-12-08 19:32:31
【问题描述】:
我在获取正确的 hbm.xml 以在链接表上映射多对一关系时遇到问题:
<class name="Car" table="Cars" lazy="true">
<id name="CarKey" type="int">
<generator class="native" />
</id>
[properties]...
<many-to-one ??? />
</class>
<class name="Driver" table="Drivers" lazy="true">
<id name="DriverKey" type="int">
<generator class="native" />
</id>
[properties]...
</class>
<class name="CarDriverLink" table="CarDriverLinks" lazy="true">
<id name="CarDriverLinkKey" type="int">
<generator class="native" />
</id>
<property name="CarKey">
<column name="CarKey" sql-type="int" not-null="true" />
</property>
<property name="DriverKey">
<column name="DriverKey" sql-type="int" not-null="true" />
</property>
</class>
想象在这个例子中,一辆汽车只能有一个司机,但一个司机可以有多辆汽车,我将如何在 Car 映射中添加多对一关系以允许汽车查看哪个司机可以驾驶它,使用 CarDriverLinks 表?
【问题讨论】:
-
我认为您正在寻找的是多对多关系
标签: c# nhibernate nhibernate-mapping