Skip to content

Calling to base after override OnModelCreating #1037

@huntertran

Description

@huntertran

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions