53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Koogle.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace Koogle.Infrastructure.Data.Configurations;
|
|
|
|
public class UserProfileClubConfiguration : IEntityTypeConfiguration<UserProfileClub>
|
|
{
|
|
public void Configure(EntityTypeBuilder<UserProfileClub> builder)
|
|
{
|
|
|
|
builder.ToTable("UserProfileClubs");
|
|
|
|
// 1 Zuordnung pro (UserProfile, Club)
|
|
builder.HasKey(x => new { x.UserProfileId, x.ClubId });
|
|
|
|
// Beziehung zu UserProfile (fehlte)
|
|
builder.HasOne(x => x.UserProfile)
|
|
.WithMany(x => x.Clubs)
|
|
.HasForeignKey(x => x.UserProfileId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
// Beziehung zu Club
|
|
builder.HasOne(x => x.Club)
|
|
.WithMany()
|
|
.HasForeignKey(x => x.ClubId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder.Property(x => x.IsDefault)
|
|
.IsRequired();
|
|
|
|
builder.Property(x => x.AssignedAt)
|
|
.IsRequired()
|
|
.HasDefaultValueSql("SYSUTCDATETIME()");
|
|
|
|
builder.Property(x => x.AssignedById)
|
|
.IsRequired();
|
|
|
|
// SQL Server: pro UserProfile nur EIN Default-Club
|
|
builder.HasIndex(x => x.UserProfileId)
|
|
.HasFilter("[IsDefault] = 1")
|
|
.IsUnique();
|
|
|
|
builder.HasIndex(x => x.ClubId);
|
|
|
|
}
|
|
}
|