concept many - to - many relationship in category entity framework

appears as: my-to-many relationship, many-to-many relationship, my-to-many relationships, my-to-many relationship, The my-to-many relationship, my-to-many relationships
Entity Framework Core in Action, SE

This is an excerpt from Manning's book Entity Framework Core in Action, SE.

Figure 2.3 The three tables involved in creating the many-to-many relationship between the Books table and the Authors table. I use a many-to-many relationship because books can have many authors, and authors may have written many books. The extra feature needed here is the Order value, because the order in which authors are listed in a book matters, so I use the Order value to display the authors in the correct sequence

EF Core 5 has a new way to handle many-to-many relationship, which will change this section, but it isn’t released yet – see https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-5.0/plan#many-to-many-navigation-properties-aka-skip-navigations for more information. This note will be replaced with an explanation of this new feature once it is released.

In EF Core, we talk about many-to-many relationships, but a relational database doesn’t directly implement many-to-many relationships. Instead, we’re dealing with two one-to-many relationships, as shown in figure 3.4.

Entity Framework Core in Action

This is an excerpt from Manning's book Entity Framework Core in Action.

Figure 2.3 The three tables involved in creating the many-to-many relationship between the Books table and the Authors table

c02-3.png

3.4.4 Updating many-to-many relationships—changing a book’s authors

In EF Core, we talk about many-to-many relationships, but a relational database doesn’t directly implement many-to-many relationships. Instead, we’re dealing with two one-to-many relationships, as shown in figure 3.4.

Listing 7.1 The Book entity class, with the relationships at the bottom
public class Book
{
    public int BookId { get; set; }
    //other scalar properties removed as not relevant…
    public PriceOffer Promotion { get; set; }    #1  
    public ICollection<BookAuthor>    #2  
        AuthorsLink { get; set; }    #2  
    public ICollection<Review> Reviews { get; set; }    #3  
}

#1   Link to an optional PriceOffer: one-to-zero-or-one relationship
#2   Link to one side of the many-to-many relationship of authors
#3   Link to any reviews for this book: one-to-many relationship
Entity Framework 4 in Action

This is an excerpt from Manning's book Entity Framework 4 in Action.

Like one-to-one relationships, many-to-many relationships are one of the causes of the granularity problem that appears in the object model. The other cause of the granularity problem is covered in the next section.

7.3.4. Persisting many-to-many relationships

Many-to-many relationships introduce nothing new. You have learned everything you need in the previous sections. To add a product to a supplier, you create the supplier and the product instances, add the product to the supplier’s list of products, and call SaveChanges.