简体   繁体   中英

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.

You have to use the fully qualified name with namespace, It takes the class name as well, but I think in your case EF Core is choosing the other context.

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>'

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

Add-Migration yourMigrationName -Context youSpecificContextName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM