我需要知道是否可以在多对多关系中添加属性,或者我应该去添加具有关系的实体? 在额外实体的情况下,如何让两个引用的表参与密钥(获取两个表的复合键)?
我遵循了这篇文章,但它不够深入:http://blog.codefluententities.com/2012/06/14/many-to-many-relationships-with-codefluent-entities/
提前致谢,
答案 0 :(得分:1)
您必须创建一个有关系的实体。这个新实体有一个复合键,因此您还必须设置setType="List"
<cf:entity name="Student">
<cf:property name="Id" key="true" />
<cf:property name="Name" />
<cf:property name="Enrollments" typeName="{0}.EnrollmentCollection" relationPropertyName="Student" />
</cf:entity>
<cf:entity name="Course">
<cf:property name="Id" key="true" />
<cf:property name="Name" />
<cf:property name="Enrollments" typeName="{0}.EnrollmentCollection" relationPropertyName="Course" />
</cf:entity>
<cf:entity name="Enrollment" setType="List">
<cf:property name="Course" key="true" typeName="{0}.Course" relationPropertyName="Enrollments" />
<cf:property name="Student" key="true" typeName="{0}.Student" relationPropertyName="Enrollments" />
<cf:property name="Prop1" />
<cf:property name="Prop2" />
</cf:entity>