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