Database improvement
1. Separate configuration files 2. Remove commented code 3. Improve entity configurations (constraints, indexes, relationships)
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user