Files
chapter-organizer/Data/Configurations/StudentConfiguration.cs
T
poprhythmandCursor 29101e2ead feat: add optional student nickname for informal display
Keep legal first and last names for formal lists; show DisplayFirstName on teams, calendars, and import matching so two Josiahs can be told apart.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-12 00:06:33 -04:00

64 lines
1.9 KiB
C#

using Core.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Data.Configurations
{
public class StudentConfiguration : IEntityTypeConfiguration<Student>
{
public void Configure(EntityTypeBuilder<Student> builder)
{
builder.HasKey(s => s.Id);
// Indexes
builder.HasIndex(s => new { s.FirstName, s.LastName });
builder.HasIndex(s => s.Email);
builder.HasIndex(s => s.Grade);
// Constraints
builder.Property(s => s.FirstName)
.IsRequired()
.HasMaxLength(100);
builder.Property(s => s.LastName)
.IsRequired()
.HasMaxLength(100);
builder.Property(s => s.Nickname)
.HasMaxLength(100);
builder.Property(s => s.Email)
.HasMaxLength(255);
builder.Property(s => s.PhoneNumber)
.HasMaxLength(20);
builder.Property(s => s.RegionalId)
.HasMaxLength(50);
builder.Property(s => s.StateId)
.HasMaxLength(50);
builder.Property(s => s.NationalId)
.HasMaxLength(50);
// Value conversion for enum
builder.Property(s => s.OfficerRole)
.HasConversion<string>()
.HasMaxLength(50);
// Relationships
// Configure the collection navigation to the join entity
builder.HasMany(s => s.EventRankings)
.WithOne(r => r.Student)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
// Many-to-many through StudentEventRanking
builder.HasMany(s => s.RankedEvents)
.WithMany()
.UsingEntity<StudentEventRanking>();
}
}
}