Implemetato databese locale con EntityFramework
This commit is contained in:
27
SteUp.Data/LocalDb/AppDbContext.cs
Normal file
27
SteUp.Data/LocalDb/AppDbContext.cs
Normal 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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user