Introduction:
Entity Framework Core (EF Core) allows creating multiple relationships between entities. However, EF Core does not directly support the connection table of customizing these relationships. This article discusses a replacement method that uses Code First to create multiple -relationships with additional fields in the association table.Create correlation:
We will create two pairs of multi -relationships instead of direct and more relationships. For example, consider the following scene:
In this scenario, the MEMBER and Comment entities have multiple relationships, and MemberComment represents the associated table of additional fields.
Query:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
<作> Operation:
In this model, adding entities and relationships similar to other CODE FIRST models:
1 2 3 4 5 |
|
Although EF Core does not directly support the multiple -to -multiple relationships in the associated tables in the association table, it can be used to create similar functions with two pairs of multi -relationships. This method allows the creation of rich correlation with additional information to achieve more flexible data modeling and query functions.
The above is the detailed content of How to Implement Many-to-Many Relationships with Extra Fields in EF Core Code First?. For more information, please follow other related articles on the PHP Chinese website!