Files
SteUP_Dotnet/SteUp.Data/LocalDb/AppDbContext.cs

27 lines
892 B
C#

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 });
}
}