dotnet / dotnet/EntityFramework.Docs

Subclassing an Existing DbContext for an Alternate Provider Causes Compilation Errors

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

Description

In Entity Framework Core 3.1, when subclassing an existing DbContext, it will generate an error if you're missing a constructor:

`public MySqliteContext(DbContextOptions<MySqliteContext> options) : base(options)`

However, this will type error, because the constructor of the base class is expecting type DbContextOptions<MyContext> for options, not DbContextOptions<MySqliteContext>.

This is discussed an in this issue, and the work around is to add a protected constructor in the base class.
https://github.com/dotnet/efcore/issues/7533#issuecomment-353669263

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 7b011c7a-3534-78e3-b491-addd96fb5ba1
* Version Independent ID: 371826c5-3ef2-4eef-32e9-d55c777cd9d3
* Content: [Migrations with Multiple Providers - EF Core](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/providers?tabs=dotnet-core-cli#feedback)
* Content Source: [entity-framework/core/managing-schemas/migrations/providers.md](https://github.com/dotnet/EntityFramework.Docs/blob/master/entity-framework/core/managing-schemas/migrations/providers.md)
* Product: **entity-framework**
* Technology: **entity-framework-core**
* GitHub Login: @bricelam
* Microsoft Alias: **bricelam**

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.