π Documentation: 20250306060435_UpdateCrewEmployeeTable.Designer.cs
Location:
IrbyImaging.DbContext/Migrations/20250306060435_UpdateCrewEmployeeTable.Designer.cs
π Table of Contents
- Overview & Purpose
- EF Core Migrations Primer
- Key Components of the Designer File
- BuildTargetModel Method Breakdown
- UML Diagram (Mermaid)
- Usage & Commands
- 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.csfile 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
CrewEmployeejoin 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! π