Implemetato databese locale con EntityFramework

This commit is contained in:
2026-02-17 17:40:33 +01:00
parent 544c9e8237
commit e7357bd78a
45 changed files with 989 additions and 119 deletions

View File

@@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore;
using SteUp.Shared.Core.Entities;
namespace SteUp.Data.LocalDb;
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
public DbSet<Ispezione> Ispezioni => Set<Ispezione>();
public DbSet<Scheda> Schede => Set<Scheda>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Ispezione>()
.HasKey(x => new { x.CodMdep, x.Data, x.Rilevatore });
modelBuilder.Entity<Scheda>()
.HasOne(x => x.Ispezione)
.WithMany(x => x.Schede)
.HasForeignKey(x => new { x.CodMdep, x.Data, x.Rilevatore })
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Scheda>()
.HasIndex(x => new { x.CodMdep, x.Data, x.Rilevatore });
}
}