简体   繁体   中英

ManyToMany association table with properties

I need to know if it is possible to add properties on a many to many Relationship or wether I should go for adding an entity with Relationship ? In the case of the extra entity, how can I get the two referenced tables to participate in the key (to get a compound key of the two tables) ?

I followed this article but it doesn't go deep enough : http://blog.codefluententities.com/2012/06/14/many-to-many-relationships-with-codefluent-entities/

Thanks in advance,

You have to create an entity with relationship. This new entity has a composite key, so you also have to set 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM