KoogleApp/src/Koogle.Infrastructure/Data/Configurations/PlayerGameStatisticsConfigu...

45 lines
1.4 KiB
C#

using Koogle.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Koogle.Infrastructure.Data.Configurations;
public class PlayerGameStatisticsConfiguration : IEntityTypeConfiguration<PlayerGameStatistics>
{
public void Configure(EntityTypeBuilder<PlayerGameStatistics> builder)
{
builder.ToTable("PlayerGameStatistics");
builder.HasKey(x => x.Id);
// Unique constraint: one stats record per player per game
builder.HasIndex(x => new { x.GameId, x.PersonId }).IsUnique();
// Game FK
builder.HasOne(x => x.Game)
.WithMany()
.HasForeignKey(x => x.GameId)
.OnDelete(DeleteBehavior.NoAction);
// Person FK
builder.HasOne(x => x.Person)
.WithMany()
.HasForeignKey(x => x.PersonId)
.OnDelete(DeleteBehavior.NoAction);
// Club FK
builder.HasOne(x => x.Club)
.WithMany()
.HasForeignKey(x => x.ClubId)
.OnDelete(DeleteBehavior.NoAction);
// Indexes for common queries
builder.HasIndex(x => x.PersonId);
builder.HasIndex(x => x.ClubId);
builder.HasIndex(x => x.GameId);
// Query filter for soft-delete
builder.HasQueryFilter(x => !x.IsDeleted && !x.Game.IsDeleted && !x.Person.IsDeleted);
}
}