35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System.Text.Json;
|
|
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 });
|
|
|
|
modelBuilder.Entity<Scheda>()
|
|
.Property(x => x.ImageNames)
|
|
.HasConversion(
|
|
v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),
|
|
v => JsonSerializer.Deserialize<List<string>>(v, (JsonSerializerOptions?)null) ?? new List<string>()
|
|
);
|
|
}
|
|
} |