Implementazione database SQLite in Program.cs
This commit is contained in:
@@ -30,9 +30,10 @@ namespace PizzaExpress
|
||||
builder.Services.AddControllers()
|
||||
.AddXmlSerializerFormatters();
|
||||
|
||||
// DB in memory perch<63> siamo froci
|
||||
// Creazione del contesto con DB SQLite
|
||||
builder.Services.AddDbContext<PizzaContext>(opt =>
|
||||
opt.UseInMemoryDatabase("dbpizze"));
|
||||
opt.UseSqlite("Data Source=pizza.db"));
|
||||
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
@@ -40,9 +41,11 @@ namespace PizzaExpress
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
using (var porcoidddioooo = app.Services.CreateScope())
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var ctx = porcoidddioooo.ServiceProvider.GetRequiredService<PizzaContext>();
|
||||
var ctx = scope.ServiceProvider.GetRequiredService<PizzaContext>();
|
||||
// Crea il DB e le tabelle basate sul modello se non esistono (no migrations)
|
||||
ctx.Database.EnsureCreated();
|
||||
SeedData.Initialize(ctx);
|
||||
}
|
||||
|
||||
@@ -56,6 +59,8 @@ namespace PizzaExpress
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user