Created
January 30, 2024 13:02
-
-
Save esersahin/4841891526b99c8a8e6b1ac7626ebdcf to your computer and use it in GitHub Desktop.
Issue-7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
using Microsoft.Extensions.DependencyInjection; | |
using TbdFriends.WaterDrinkWater.Data.Contexts; | |
namespace TbdFriends.WaterDrinkWater.Data.Extensions; | |
public static class MigrationExtension | |
{ | |
public static void ApplyMigrations(this IServiceProvider services) | |
{ | |
using var scope = services.CreateScope(); | |
var factory = scope.ServiceProvider.GetRequiredService<IDbContextFactory<ApplicationDbContext>>(); | |
using var context = factory.CreateDbContext(); | |
context.Database.Migrate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use the extension, add the following line to program.cs.
app.Services.ApplyMigrations();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}