Initial Migration Done
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -22,4 +25,20 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
var dbContext = services.GetRequiredService<HealthcareManagerContext>(); // Directly resolving your DbContext
|
||||
EnsureDatabaseCreated(dbContext);
|
||||
}
|
||||
|
||||
app.Run();
|
||||
|
||||
static void EnsureDatabaseCreated(HealthcareManagerContext dbContext)
|
||||
{
|
||||
// Checking for pending migrations is more efficient than applying migrations unconditionally
|
||||
if (dbContext.Database.GetPendingMigrations().Any())
|
||||
{
|
||||
dbContext.Database.Migrate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user