Skip to content

Instantly share code, notes, and snippets.

@ankittyagii
Last active April 18, 2020 21:14
Show Gist options
  • Save ankittyagii/600ce0a72256c4e19e62b392c4f4b891 to your computer and use it in GitHub Desktop.
Save ankittyagii/600ce0a72256c4e19e62b392c4f4b891 to your computer and use it in GitHub Desktop.
Add Migration In Different Assembly.
#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