Last active
April 18, 2020 21:14
-
-
Save ankittyagii/600ce0a72256c4e19e62b392c4f4b891 to your computer and use it in GitHub Desktop.
Add Migration In Different Assembly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if you want your migration in different assembly and your DbContext lies in different project, then you can use the strategy to maintain multiple sets of migrations | |
#As a example, you have ASP.Net Core MVC project Named - AspNetCoreDemo.Web and AspNetCoreDemo.Migrations library | |
#Open Startup File in "AspNetCoreDemo.Web" add the below code in ConfigureServices method | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddDbContext<AppDBContext>(options => | |
{ | |
options.UseSqlServer(Configuration["ConnectionStrings:default"],b=>b.MigrationsAssembly("AspNetCoreDemo.Migrations")); | |
}); | |
} | |
#Run This command to add the migration | |
#1. Using package console. | |
Add-Migration "Initial" -Project AspNetCoreDemo.Migrations | |
#2. Using .Net CLI | |
dotnet ef migrations add "Initial" --project AspNetCoreDemo.Migrations | |
#Happy Learning. | |
#anvitte #anvittecsharpaspnetcore #opensourcelearningplatform #aspnetcore #entityframeworkmigrations | |
#migrationstrategy | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment