using MaBibli.Shared.Entites; using Microsoft.EntityFrameworkCore; namespace MaBibli.Api.Data; public class MaBibliDbContext(DbContextOptions options) : DbContext(options) { public DbSet Livres => Set(); public DbSet Prets => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity(livre => { livre.Property(l => l.Titre).IsRequired(); livre.HasIndex(l => l.Isbn); livre.HasMany(l => l.Prets) .WithOne(p => p.Livre) .HasForeignKey(p => p.LivreId) .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity(pret => { pret.Property(p => p.Emprunteur).IsRequired(); pret.HasIndex(p => p.LivreId); }); } }