Skip to content

Instantly share code, notes, and snippets.

@danielmackay
Created December 28, 2023 04:09
Show Gist options
  • Save danielmackay/edf58c4987bc5a188214f4e348fec840 to your computer and use it in GitHub Desktop.
Save danielmackay/edf58c4987bc5a188214f4e348fec840 to your computer and use it in GitHub Desktop.
Apply Migrations Extension Method
public static class MigrationExtensions
{
public static void ApplyMigrations(this IApplicationBuilder app)
{
using IServiceScope scope = app.ApplicationServices.CreateScope();
using ApplicationDbContext dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
dbContext.Database.Migrate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment