dotnet / dotnet/EntityFramework.Docs

Calling to base after override OnModelCreating

Open
#1,037 0 comments 0 reactions 0 assignees View on GitHub
area-model-building
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

Using EFCore with IdentityCore, after override OnModelCreating, you have to call base method to be able to create database for the first time

```csharp
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity()
.HasKey(t => new { t.PostId, t.CategoryId });
modelBuilder.Entity()
.HasOne(pt => pt.Post)
.WithMany(p => p.PostCategories)
.HasForeignKey(pt => pt.PostId);
modelBuilder.Entity()
.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](https://docs.microsoft.com/en-us/ef/core/modeling/relationships)
* Content Source: [entity-framework/core/modeling/relationships.md](https://github.com/aspnet/EntityFramework.Docs/blob/master/entity-framework/core/modeling/relationships.md)
* Product: **entity-framework**
* GitHub Login: @rowanmiller
* Microsoft Alias: **divega**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.