Merge del branch di implementazione SQLite
Reviewed-on: SmerdoRepository/PizzaExpress#1
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -54,3 +54,4 @@ TestResult.xml
|
|||||||
nunit-*.xml
|
nunit-*.xml
|
||||||
|
|
||||||
.vs/
|
.vs/
|
||||||
|
pizza.db*
|
||||||
@@ -18,14 +18,6 @@ namespace PizzaExpress.Data
|
|||||||
public static void Initialize(PizzaContext ctx)
|
public static void Initialize(PizzaContext ctx)
|
||||||
{
|
{
|
||||||
if (ctx.Pizze.Any()) return;
|
if (ctx.Pizze.Any()) return;
|
||||||
|
|
||||||
ctx.Pizze.AddRange(
|
|
||||||
new Pizza { Id = 1, Nome = "Margherita", Prezzo = 4.50m },
|
|
||||||
new Pizza { Id = 2, Nome = "Prosciutto", Prezzo = 5.00m },
|
|
||||||
new Pizza { Id = 3, Nome = "Capricciosa", Prezzo = 7.00m }
|
|
||||||
);
|
|
||||||
|
|
||||||
ctx.SaveChanges();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.10" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.11" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -30,9 +30,10 @@ namespace PizzaExpress
|
|||||||
builder.Services.AddControllers()
|
builder.Services.AddControllers()
|
||||||
.AddXmlSerializerFormatters();
|
.AddXmlSerializerFormatters();
|
||||||
|
|
||||||
// DB in memory perch<63> siamo froci
|
// Creazione del contesto con DB SQLite
|
||||||
builder.Services.AddDbContext<PizzaContext>(opt =>
|
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
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
@@ -40,9 +41,11 @@ namespace PizzaExpress
|
|||||||
|
|
||||||
var app = builder.Build();
|
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);
|
SeedData.Initialize(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +59,8 @@ namespace PizzaExpress
|
|||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
PizzaExpress/pizza.example.db
Normal file
BIN
PizzaExpress/pizza.example.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user