17 lines
490 B
C#
17 lines
490 B
C#
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace WebNovelPortalAPI.Extensions;
|
|
|
|
public static class DBUpdateExtensions
|
|
{
|
|
public static void UpdateDatabase<T>(this IApplicationBuilder app) where T : DbContext
|
|
{
|
|
using var serviceScope = app.ApplicationServices.CreateScope();
|
|
using var context = serviceScope.ServiceProvider.GetService<T>();
|
|
|
|
if (context.Database.GetPendingMigrations().Any())
|
|
{
|
|
context.Database.Migrate();
|
|
}
|
|
}
|
|
} |