Add Migration - bondaigames/ASP.NET-Core-Documentation GitHub Wiki
app.MapControllers();
ApplyMigration();
app.Run();
void ApplyMigration()
{
using (var scope = app.Services.CreateScope())
{
var _db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
if (_db.Database.GetPendingMigrations().Count() > 0)
{
_db.Database.Migrate();
}
}
}