Skip to content

Calling to base after override OnModelCreating #1037

Open

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions