πŸ“‘ Documentation: 20250306060435_UpdateCrewEmployeeTable.Designer.cs

Location:
IrbyImaging.DbContext/Migrations/20250306060435_UpdateCrewEmployeeTable.Designer.cs


πŸ“‹ Table of Contents

  1. Overview & Purpose
  2. EF Core Migrations Primer
  3. Key Components of the Designer File
  4. BuildTargetModel Method Breakdown
  5. UML Diagram (Mermaid)
  6. Usage & Commands
  7. Conclusion

1. Overview & Purpose

This file is an auto‑generated EF Core designer snapshot for the migration:

Migration Name: 20250306060435_UpdateCrewEmployeeTable
Role: Captures the model’s state after applying this migration.

πŸ’‘ Why it exists:

  • EF Core uses it to compare model snapshots (before/after) and generate SQL DDL.
  • It is not intended for manual editing.

2. EF Core Migrations Primer

  • Migration: A set of operations (Up/Down) that adjust database schema.
  • Designer (.Designer.cs): Holds BuildTargetModel() to rebuild the EF model snapshot at this point in time.
  • Model Snapshot: A C# representation of all your entities, properties, relations, etc.

3. Key Components of the Designer File

Section Description
using directives Brings in EF Core & SQL Server extensions
[DbContext(...)] Associates migration with IrbyContext
[Migration("...")] Stamp identifying this migration
partial class … Contains only BuildTargetModel()
BuildTargetModel(...) Reconstructs the full EF Core model after migration
[DbContext(typeof(IrbyContext))]
[Migration("20250306060435_UpdateCrewEmployeeTable")]
partial class UpdateCrewEmployeeTable
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        // … all entities and relationships …
    }
}

4. BuildTargetModel Method Breakdown

4.1 Model Annotations

At the very top, global annotations configure the entire model:

modelBuilder
  .HasAnnotation("ProductVersion", "9.0.0")
  .HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
  • ProductVersion: EF Core version used.
  • MaxIdentifierLength: Limits table/column name size to fit SQL Server.
  • UseIdentityColumns: Globally enables IDENTITY (auto‑increment) for keys.

4.2 Entity Configuration Highlights

Every domain class maps to a table/schema:

  • Properties: .Property<T>("Name").HasColumnType("...")
  • Keys: .HasKey("PK_Column") or composite keys
  • Indexes: .HasIndex("ColumnName")
  • Table Mapping: .ToTable("TableName", "irby")

πŸ€– EF generated 100+ entitiesβ€”here we focus on the CrewEmployee changes.


4.3 CrewEmployee Table Changes

This migration introduces audit and classification fields to the join table irby.CrewEmployee.

Column Type Notes
CrewId uniqueidentifier PK, FK β†’ irby.Crew.CrewId
EmployeeId uniqueidentifier PK, FK β†’ irby.Employee.EmployeeId
CostCodeId uniqueidentifier FK β†’ irby.CostCode.CostCodeId
CreatedBy nvarchar(max) New: tracks who added the record
CreatedDate nvarchar(max) New: date string of creation
IsDeleted bit New: soft‑delete flag
JobClassificationId uniqueidentifier New: FK β†’ irby.JobClassification
modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEmployee", b =>
{
    b.Property<Guid>("CrewId")
      .HasColumnType("uniqueidentifier");
    b.Property<Guid>("EmployeeId")
      .HasColumnType("uniqueidentifier");
    b.Property<Guid>("CostCodeId")
      .HasColumnType("uniqueidentifier");

    // ─── ADDED FIELDS ───────────────────────────────
    b.Property<string>("CreatedBy")
      .HasColumnType("nvarchar(max)");
    b.Property<string>("CreatedDate")
      .HasColumnType("nvarchar(max)");
    b.Property<bool>("IsDeleted")
      .HasColumnType("bit");
    b.Property<Guid>("JobClassificationId")
      .HasColumnType("uniqueidentifier");
    // ────────────────────────────────────────────────

    b.HasKey("CrewId", "EmployeeId");
    b.HasIndex("CostCodeId");
    b.HasIndex("EmployeeId");
    b.HasIndex("JobClassificationId");

    b.ToTable("CrewEmployee", "irby");
});

βš™οΈ Why these fields?

  • Audit: Know who/when joined crews.
  • Soft‑delete: Retain historical assignments.
  • Classification: Link each crew‑employee to a JobClassification for payroll/reporting.

4.4 Relationship Mapping

Below the property blocks, EF Core wires up foreign keys & navigations:

modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEmployee", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.CostCode", "CostCode")
     .WithMany()
     .HasForeignKey("CostCodeId")
     .OnDelete(DeleteBehavior.Restrict)
     .IsRequired();

    b.HasOne("IrbyImaging.DomainClasses.Crew", "Crew")
     .WithMany("CrewEmployees")
     .HasForeignKey("CrewId")
     .OnDelete(DeleteBehavior.Restrict)
     .IsRequired();

    b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
     .WithMany("CrewEmployees")
     .HasForeignKey("EmployeeId")
     .OnDelete(DeleteBehavior.Restrict)
     .IsRequired();

    b.HasOne("IrbyImaging.DomainClasses.JobClassification", "JobClassification")
     .WithMany()
     .HasForeignKey("JobClassificationId")
     .OnDelete(DeleteBehavior.Restrict)
     .IsRequired();
});
  • Restrict: Prevents orphaned or cascading deletesβ€”maintains data integrity.
  • WithMany: Models 1:N from each parent to CrewEmployee.

5. UML Diagram (Mermaid)

classDiagram
    class CrewEmployee {
      +Guid CrewId (PK, FK)
      +Guid EmployeeId (PK, FK)
      +Guid CostCodeId (FK)
      +string CreatedBy
      +string CreatedDate
      +bool IsDeleted
      +Guid JobClassificationId (FK)
    }
    class Crew {
      +Guid CrewId
      +string CrewName
    }
    class Employee {
      +Guid EmployeeId
      +string FirstName
      +string LastName
    }
    class CostCode {
      +Guid CostCodeId
      +string CostCodeNumber
    }
    class JobClassification {
      +Guid JobClassificationId
      +string Name
    }

    Crew "1" -- "0..*" CrewEmployee : hasMembers
    Employee "1" -- "0..*" CrewEmployee : servesOn
    CostCode "1" -- "0..*" CrewEmployee : allocatedVia
    JobClassification "1" -- "0..*" CrewEmployee : classifiedAs

6. Usage & Commands

To create or apply this migration in your project:

# 1. Add the migration (if not already generated)
dotnet ef migrations add UpdateCrewEmployeeTable

# 2. Inspect the generated files:
#    - 20250306060435_UpdateCrewEmployeeTable.cs      (Up/Down operations)
#    - 20250306060435_UpdateCrewEmployeeTable.Designer.cs  (this snapshot)

# 3. Update database:
dotnet ef database update
  • πŸ“Œ The .Designer.cs file updates automatically.
  • πŸ”’ Do not manually alter this file.

7. Conclusion

This designer snapshot captures the evolving schema of your EF Core model as of the UpdateCrewEmployeeTable migration. It:

  • πŸ“ˆ Introduces audit & classification columns to the CrewEmployee join table
  • πŸ”— Configures foreign‑key relationships & indexes
  • πŸ› οΈ Provides a reference for EF’s diffing engine

πŸš€ Next Steps:

  • Inspect the Up()/Down() logic in 20250306060435_UpdateCrewEmployeeTable.cs.
  • Run integration tests to ensure data integrity.

Happy coding! πŸŽ‰