Fix database initializing
This commit is contained in:
parent
25a9038fec
commit
a652c2672c
2 changed files with 7 additions and 4 deletions
|
@ -20,15 +20,11 @@ namespace NG_2023_Kanban.DataLayer.DbStartup
|
||||||
|
|
||||||
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
|
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
|
||||||
|
|
||||||
optionsBuilder.UseSqlServer(configuration["ConnectionString"]);
|
|
||||||
|
|
||||||
services.AddDbContext<DatabaseContext>(options =>
|
services.AddDbContext<DatabaseContext>(options =>
|
||||||
{
|
{
|
||||||
options.UseSqlServer(
|
options.UseSqlServer(
|
||||||
configuration["ConnectionString"]);
|
configuration["ConnectionString"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
(new DatabaseContext(optionsBuilder.Options)).Database.EnsureCreated(); // possibly misplaced
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,13 @@ if (!app.Environment.IsDevelopment())
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var serviceProvider = scope.ServiceProvider;
|
||||||
|
var context = serviceProvider.GetRequiredService<DatabaseContext>();
|
||||||
|
DbInitializer.Initialize(context);
|
||||||
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
|
|
Reference in a new issue