liveBook · Manning

Many-to-many relationship

As explained in Building Web APIs with ASP.NET Core

A many-to-many relationship is a data-model relationship in which multiple instances of each of two entity types can be associated with multiple instances of the other.

A many-to-many relationship connects multiple instances of one entity type to multiple instances of another. In a relational SQL schema, a junction table records those associations. section 4.4.3 section 4.1.1

Implement the relationship by:

  • Creating the two related entities and their database tables. section 4.4.3
  • Adding a junction entity with the minimum required properties. section 4.4.3
  • Defining navigation properties, foreign keys, cascading rules, and DbSets in the application database context through the Fluent API. section 4.4.3

Board games and categories

A BoardGame can belong to one or more categories, while each Category can describe multiple board games. The Categories table and BoardGames_Categories junction table represent that relationship. section 4.4.3

Figure 4.1 MyBGList database schema diagram for a table-oriented SQL database
04-01

Use the relational schema diagram to inspect the main tables, related tables, and junction-table links in the board-game data model. section 4.1.1

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines junction entities and descends into navigation properties, foreign keys, cascading rules, DbSets, and Fluent API configuration.
Examples
Uses BoardGame–Domain, BoardGame–Mechanic, and BoardGame–Category associations represented through junction tables.
What you can do after
Build it from scratch by defining related entities, a junction entity, and database-context relationship configuration.
How it connects
Connects SQL databases with relational schemas, junction tables, foreign keys, navigation properties, Fluent API, and JOINs.

Also explained in

Compare how 5 books explain many-to-many relationship →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.