EntityFramework.Docs icon indicating copy to clipboard operation
EntityFramework.Docs copied to clipboard

Calling to base after override OnModelCreating

Open huntertran opened this issue 7 years ago • 0 comments

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.

huntertran avatar Oct 07 '18 05:10 huntertran