Initial Migration Done

This commit is contained in:
andrei-mihnea-cerbu
2024-04-04 16:28:11 +03:00
parent d43beb66b6
commit 041abb5900
130 changed files with 2274 additions and 146 deletions
+19
View File
@@ -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();
}
}