Home >Backend Development >C++ >How to Implement a Many-to-Many Relationship with Additional Properties in EF Core?
Use the associated table in EF Core to create a multi -to -many relationship
Configure associated with Fluent API
<code class="language-csharp">public class Member { public int MemberID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public virtual ICollection<MemberComment> MemberComments { get; set; } } public class Comment { public int CommentID { get; set; } public string Message { get; set; } public virtual ICollection<MemberComment> MemberComments { get; set; } } public class MemberComment { [Key, Column(Order = 0)] public int MemberID { get; set; } [Key, Column(Order = 1)] public int CommentID { get; set; } public virtual Member Member { get; set; } public virtual Comment Comment { get; set; } public int Something { get; set; } public string SomethingElse { get; set; } }</code>
Alternative: Create two pairs of multi -relationships
MemberComment
(The code segment is the same as input, the duplicate here is omitted)
Use association
Now, we can perform various operations on these entities:Get the member's comment
The above is the detailed content of How to Implement a Many-to-Many Relationship with Additional Properties in EF Core?. For more information, please follow other related articles on the PHP Chinese website!