PlayerManagement/Database/Configurations/CustomEventParticipantConfiguration.cs
Tomasi - Developing 35e83c4735 beta 0.0.3
2024-11-26 08:43:01 +01:00

29 lines
1.5 KiB
C#

using Database.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Database.Configurations;
public class CustomEventParticipantConfiguration : IEntityTypeConfiguration<CustomEventParticipant>
{
public void Configure(EntityTypeBuilder<CustomEventParticipant> builder)
{
builder.HasKey(customEventParticipant => customEventParticipant.Id);
builder.Property(customEventParticipant => customEventParticipant.Id).ValueGeneratedNever();
builder.Property(customEventParticipant => customEventParticipant.PlayerId).IsRequired();
builder.Property(customEventParticipant => customEventParticipant.CustomEventId).IsRequired();
builder.Property(customEventParticipant => customEventParticipant.Participated).IsRequired(false);
builder.Property(customEventParticipant => customEventParticipant.AchievedPoints).IsRequired(false);
builder.HasOne(customEventParticipant => customEventParticipant.Player)
.WithMany(player => player.CustomEventParticipants)
.HasForeignKey(customEventParticipant => customEventParticipant.PlayerId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne(customEventParticipant => customEventParticipant.CustomEvent)
.WithMany(customEvent => customEvent.CustomEventParticipants)
.HasForeignKey(customEventParticipant => customEventParticipant.CustomEventId)
.OnDelete(DeleteBehavior.Cascade);
}
}