I use the following CLI for DB Migrations:
dotnet ef migrations add <Name-of-Migration>dotnet ef database update
However, I am looking for a way for this to happen automatically: when a change in the Model is detected.
So far, I have been able to eliminate Step 2 by doing the following in Startup.cs:
private void SetupDatabase(IApplicationBuilder app)
{
using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
//Migate any pending changes:
context.Database.Migrate();
}
}
This migrates any pending changes created by doing:
dotnet ef migrations add <Name-of-Migration>
but it does not add migration for any changes in the model. How do I automate this migrations add?