826eac1372
1. Separate configuration files 2. Remove commented code 3. Improve entity configurations (constraints, indexes, relationships)
34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using Core.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace Data.Configurations
|
|
{
|
|
public class StudentEventRankingConfiguration : IEntityTypeConfiguration<StudentEventRanking>
|
|
{
|
|
public void Configure(EntityTypeBuilder<StudentEventRanking> builder)
|
|
{
|
|
// Note: Relationships are configured in StudentConfiguration
|
|
// This configuration only defines keys, indexes, and constraints
|
|
|
|
// Composite key on shadow properties created by EF Core
|
|
builder.HasKey("StudentId", "EventDefinitionId");
|
|
|
|
// Indexes on shadow properties
|
|
builder.HasIndex(r => r.Rank);
|
|
builder.HasIndex("StudentId");
|
|
builder.HasIndex("EventDefinitionId");
|
|
|
|
// Constraints
|
|
builder.Property(r => r.Rank)
|
|
.IsRequired();
|
|
|
|
// Relationship to EventDefinition (Student relationship is in StudentConfiguration)
|
|
builder.HasOne(r => r.EventDefinition)
|
|
.WithMany()
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|
|
}
|