using Koogle.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Koogle.Infrastructure.Data.Configurations; public class PersonConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("Persons"); builder.HasKey(x => x.Id); builder.Property(x => x.Name) .HasMaxLength(200) .IsRequired(); builder.Property(x => x.PersonStatus) .HasConversion() .IsRequired(); builder.Property(x => x.ClubId) .IsRequired(); builder.HasOne(x => x.Club) .WithMany() .HasForeignKey(x => x.ClubId) .OnDelete(DeleteBehavior.Restrict); // Alternate Key für DayPerson-Composite FK: (Id, ClubId) builder.HasAlternateKey(x => new { x.Id, x.ClubId }); builder.HasMany(x => x.Expenses) .WithOne(x => x.Person) .HasForeignKey(x => x.PersonId) .OnDelete(DeleteBehavior.Cascade); builder.HasIndex(x => x.ClubId); builder.HasQueryFilter(x => !x.IsDeleted); // Wichtig: // Keine HasMany(x => x.DayPersons) hier definieren, weil die Club-Konsistenz // via Composite-FK in DayPersonConfiguration abgebildet wird. } }