自选项目实验优化

This commit is contained in:
2026-08-11 09:29:44 +08:00 Unverified
parent 9b32ee916c
commit e69ab6f580
11 changed files with 7578 additions and 67 deletions
@@ -51,6 +51,8 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
Set<ClassroomReservation>();
public DbSet<ExperimentProject> ExperimentProjects => Set<ExperimentProject>();
public DbSet<ExperimentSession> ExperimentSessions => Set<ExperimentSession>();
public DbSet<ExperimentSessionInstructor> ExperimentSessionInstructors =>
Set<ExperimentSessionInstructor>();
public DbSet<ExperimentBooking> ExperimentBookings => Set<ExperimentBooking>();
public DbSet<ExperimentGradeSheet> ExperimentGradeSheets =>
Set<ExperimentGradeSheet>();
@@ -690,6 +692,8 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
entity.Property(x => x.Name).HasMaxLength(120);
entity.Property(x => x.Description).HasMaxLength(1000);
entity.Property(x => x.Requirements).HasMaxLength(1000);
entity.Property(x => x.SelectionStartsAt).HasConversion<UtcDateTimeConverter>();
entity.Property(x => x.SelectionEndsAt).HasConversion<UtcDateTimeConverter>();
// 集中安排会为同一教学任务的每一条实验课表记录生成项目;
// 自行安排仍由控制器保持“教学任务 + 编码”唯一。
entity.HasIndex(x => new
@@ -805,6 +809,19 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
.OnDelete(DeleteBehavior.Restrict);
});
builder.Entity<ExperimentSessionInstructor>(entity =>
{
entity.HasIndex(x => new { x.ExperimentSessionId, x.TeacherId })
.IsUnique();
entity.HasIndex(x => x.TeacherId);
entity.HasOne(x => x.ExperimentSession).WithMany(x => x.Instructors)
.HasForeignKey(x => x.ExperimentSessionId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(x => x.Teacher).WithMany()
.HasForeignKey(x => x.TeacherId)
.OnDelete(DeleteBehavior.Restrict);
});
builder.Entity<ExperimentCourseGrade>(entity =>
{
entity.Property(x => x.WeightedAverageScore).HasPrecision(5, 1);