50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
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 DayConfiguration : IEntityTypeConfiguration<Day>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Day> builder)
|
|
{
|
|
|
|
builder.ToTable("Days");
|
|
|
|
builder.HasKey(x => x.Id);
|
|
|
|
builder.Property(x => x.PostDate)
|
|
.IsRequired();
|
|
|
|
builder.Property(x => x.Status)
|
|
.HasConversion<int>()
|
|
.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.HasIndex(x => new { x.ClubId, x.PostDate });
|
|
|
|
builder.HasQueryFilter(x => !x.IsDeleted);
|
|
|
|
// Wichtig:
|
|
// Keine HasMany(x => x.DayPersons) hier definieren, weil die Club-Konsistenz
|
|
// via Composite-FK in DayPersonConfiguration abgebildet wird.
|
|
|
|
}
|
|
}
|