2 回答
TA贡献1946条经验 获得超3个赞
不要使用外来的关联映射。
真正的多到多关联的良好用法是罕见的。大多数情况下,您需要存储在“链接表”中的其他信息。在这种情况下,对中间链接类使用两个一对多的关联要好得多。事实上,我们认为大多数的关联是一对多的和多对一的,在使用任何其他的关联风格时,你应该小心,并问自己是否真的有必要。
Author
Work
:
<class name="Work" table="works" ...> <id name="Id" column="id" generator="native" /> ... <set name="Authors" table="author_work" lazy="true"> <key> <column name="work_id" not-null="true"/> </key> <many-to-many class="Author"> <column name="author_id" not-null="true"/> </many-to-many> </set></class>
<class name="Author" table="authors"> ... <set name="Works" table="author_work" inverse="true" lazy="true"> <key column="author_id"/> <many-to-many class="Work" column="work_id"/> </set></class>
AuthorWork
public class AuthorWork{ public virtual Author Author { get; set; } public virtual Work Work { get; set; } public virtual int OrderBy { get; set; }}
<class name="AuthorWork" table="author_work"> ... <many-to-one name="Author" column="author_id" /> <many-to-one name="Workr" column="work_id" /> <property name="OrderBy" />
<set name="Authors" lazy="true" order-by="OrderBy"> <key column="work_id" not-null="true"/> <one-to-many class="AuthorWork" /></set>
注:必须同意这一建议,在综述中提出的要求越多,我们就越高兴我们有办法来管理这种关系!
TA贡献1847条经验 获得超7个赞
User
Role
User one-to-many UserRoles many-to-one Role
User
, Role
UserRoles
UserRoles
User
Role
User
Role
UserRoles
添加回答
举报