using Koogle.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Koogle.Infrastructure.Data.Configurations; public class GameConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("Games", t => { // Optional, aber sehr nützlich: JSON-Validierung in SQL Server // Entfernen, falls GameData nicht zwingend JSON enthalten muss. t.HasCheckConstraint("CK_Games_GameData_IsJson", "ISJSON([GameData]) > 0"); }); builder.HasKey(x => x.Id); // JSON-State: explizit nvarchar(max) builder.Property(x => x.GameData) .IsRequired() .HasColumnType("nvarchar(max)"); // Day-FK builder.Property(x => x.DayId) .IsRequired(); // Day hat in deinem Modell keine Navigation "Games" => WithMany() ist korrekt builder.HasOne(x => x.Day) .WithMany() .HasForeignKey(x => x.DayId) .OnDelete(DeleteBehavior.Cascade); // Mehrere Games pro Day -> Index nicht unique builder.HasIndex(x => x.DayId); // SoftDelete QueryFilter (nur wenn du es nicht global im DbContext setzt) builder.HasQueryFilter(x => !x.IsDeleted); // Hinweis: // Die Beziehung Game <-> GamePerson wird idealerweise vollständig // in GamePersonConfiguration konfiguriert (Key + FKs + DeleteBehavior). // Daher hier keine zusätzliche HasMany(x => x.GamePersons) nötig. } }