Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core 3.1 Add Migration on specific DB Context

I have 2 EF Core DBContexts in my WebAPI project.

One is an OracleContext - Oracle.EntityFrameworkCore(2.19.70).

The OracleContext is an existing database where I have already made repositories for querying read-only data.

Second is an SQLServerContext - EFCore(3.1.5)

The SQLServerContext is a code-first approach for writing the rest of the app's functionality.

Whenever I try to run Add-Migration InitialCreate -Context SQLServerContext -OutputDir Migrations\SqlServerMigrations it gives me an error:

Method 'get_Info' in type 'Oracle.EntityFrameworkCore.Infrastructure.Internal.OracleOptionsExtension' from assembly 'Oracle.EntityFrameworkCore, Version=2.0.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342' does not have an implementation.

I believe Add-Migration is also trying to execute the OracleContext but I wanted the SQLServerContext only to generate migration files, How can I achieve this?

[EDIT] - Each DBContexts lives on its own dotnet core library classes. - WebAPI project is the startup project.

like image 791
AlwaysHungry Avatar asked Oct 23 '25 18:10

AlwaysHungry


2 Answers

For Add Migration In Asp.Net Core 3.1 in visual studio use below code:

Add-Migration yourMigrationName -Context youSpecificContextName
like image 152
RezaAmirian Avatar answered Oct 25 '25 08:10

RezaAmirian


Need to specify the context. In terminal, switch to project which contains migration folder. Use below command

dotnet ef migrations add --context YourApp.YourAppDbContext '<MigrationName>'
like image 44
Ravi Avatar answered Oct 25 '25 09:10

Ravi