Is it possible to have my ASP Core Web API ensure the DB is migrated to the latest migration using EF Core? I know this can be done through the command line, but I want to
Based on the answer of @steamrolla I would propose the following improvement:
public static class EnsureMigration
{
public static void EnsureMigrationOfContext(this IApplicationBuilder app) where T:DbContext
{
var context = app.ApplicationServices.GetService();
context.Database.Migrate();
}
}
With this you can also ensure the migration of different contexts, e.g. if you have a Identity database.
Usage:
app.EnsureMigrationOfContext();