EntityFramework.Docs
EntityFramework.Docs copied to clipboard
Calling to base after override OnModelCreating
Using EFCore with IdentityCore, after override OnModelCreating, you have to call base method to be able to create database for the first time
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<PostCategory>()
.HasKey(t => new { t.PostId, t.CategoryId });
modelBuilder.Entity<PostCategory>()
.HasOne(pt => pt.Post)
.WithMany(p => p.PostCategories)
.HasForeignKey(pt => pt.PostId);
modelBuilder.Entity<PostCategory>()
.HasOne(pt => pt.Category)
.WithMany(t => t.PostCategories)
.HasForeignKey(pt => pt.CategoryId);
base.OnModelCreating(modelBuilder);
}
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 24b2b50e-35f8-9e0b-8ce5-840e1ea816e6
- Version Independent ID: 9e0e6e2c-48fa-76c3-3bd9-813a6df22645
- Content: Relationships - EF Core
- Content Source: entity-framework/core/modeling/relationships.md
- Product: entity-framework
- GitHub Login: @rowanmiller
- Microsoft Alias: divega