A navigation property is an entity property that directly references one related entity or a collection of related entities. In EF Core, it provides an object-level way to work with relationships between database records. section 4.3.3
For the board-game model, navigation properties connect BoardGame with Domain, Mechanic, and their junction entities. Add reciprocal properties to both sides, then configure the relationships so EF Core can populate the references. section 4.3.3
Use the property shape that matches the relationship:
- Use a nullable entity property for a direct reference, such as BoardGame? or Domain? on a junction entity. section 4.3.3
- Use a nullable ICollection<T> property for the related collection, such as BoardGames_Domains on BoardGame or Domain. section 4.3.3
- Configure each reference with the Fluent API, linking HasOne, WithMany, HasForeignKey, requiredness, and delete behavior. section 4.3.3
Board games and domains
A BoardGames_Domains junction entity can expose BoardGame? BoardGame and Domain? Domain. BoardGame and Domain can each expose ICollection<BoardGames_Domains>? BoardGames_Domains. Fluent API then maps BoardGameId and DomainId as foreign keys and configures cascading deletes. section 4.3.3
Publisher relationship
A one-to-many Publisher–BoardGame relationship uses navigation properties on both entities, a required PublisherId foreign key on BoardGame, cascading rules, and a Publisher DbSet in ApplicationDbContext. section 4.4.2
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<BoardGames_Domains>()
.HasKey(i => new { i.BoardGameId, i.DomainId });
modelBuilder.Entity<BoardGames_Domains>()
.HasOne(x => x.BoardGame)
.WithMany(y => y.BoardGames_Domains)
.HasForeignKey(f => f.BoardGameId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<BoardGames_Domains>()
.HasOne(o => o.Domain)
.WithMany(m => m.BoardGames_Domains)
.HasForeignKey(f => f.DomainId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<BoardGames_Mechanics>()
.HasKey(i => new { i.BoardGameId, i.MechanicId });
modelBuilder.Entity<BoardGames_Mechanics>()
.HasOne(x => x.BoardGame)
.WithMany(y => y.BoardGames_Mechanics)
.HasForeignKey(f => f.BoardGameId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<BoardGames_Mechanics>()
.HasOne(o => o.Mechanic)
.WithMany(m => m.BoardGames_Mechanics)
.HasForeignKey(f => f.MechanicId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
}
Inspect the Fluent API configuration that connects junction navigation properties with foreign keys, collections, required relationships, and cascading deletes. section 4.3.3


