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