Click here to Skip to main content
15,891,712 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Asp net core 3 application visual studio it has the following :

project as RazorPages with the structure wwwroot, Models, Pages, Services, appsettings, Startup, and Program

Folders:

- Model => PrimaryDBContext => It is my primary DBcontext, I need to set up this context in Startup as primary and the context from DataService as secondary

- Services => DataService: It has the secondary DBContext (I have it as my secondary context from a main project that contains Users (table) ). I use this DBContext for Login (to claim user identity) to use it only for email and Password credentials.

-appsettings => It has the two connections string for my primary and secondary context


The issue is when I want to create migration is says that there is a conflict between the context. It does not allow to create the migration for the project.

How could I set up my primary context and secondary context to create migration?
(I don't want to include secondary context for migration)

How could I define in the project that my primary context is the context to pick up for the migration?

thank you in advance

What I have tried:

C#
//In Startup I set up ConnStrings

 public void ConfigureServices(IServiceCollection services)
{

services.AddScoped<IDataService, DataService>();

services.AddDbContext<PrimaryDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("PrimaryDbConnString")));

services.AddScoped<SecondaryDbContext>(options => new SecondaryDbContext(Configuration.GetConnectionString("SecondaryConnString")));


}
Posted
Updated 3-Jun-20 0:27am

1 solution

You'll need to specify which context you're adding the migration for:
Package
Add-Migration InitialCreate -Context PrimaryDbContext -OutputDir Migrations\PrimaryDbContext
Add-Migration InitialCreate -Context SecondaryDbContext -OutputDir Migrations\SecondaryDbContext
.NET
dotnet ef migrations add InitialCreate --context PrimaryDbContext --output-dir Migrations/PrimaryDbContext
dotnet ef migrations add InitialCreate --context SecondaryDbContext --output-dir Migrations/SecondaryDbContext
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900