๐ Documentation: 20250306035117_AddCrewEmployeeTable.Designer.cs
๐ Table of Contents
- ๐โโ๏ธ Overview & Purpose
- โ๏ธ Dependencies & Technologies
- ๐๏ธ Key Functional Areas
- โ Changes Introduced:
CrewEmployeeTable - ๐ Entity Mapping in
BuildTargetModel - ๐
CrewEmployeeTable Definition - ๐งฉ Relationships & Navigation Properties
- ๐ง Usage Examples & Code Snippets
- ๐ UML Diagram
- ๐ How to Run the Migration
- ๐ Conclusion
๐โโ๏ธ Overview & Purpose
This file is an autoโgenerated Entity Framework Core migration snapshot.
- Location:
IrbyImaging.DbContext/Migrations/20250306035117_AddCrewEmployeeTable.Designer.cs - Class:
AddCrewEmployeeTable(partial) - Method:
BuildTargetModel(ModelBuilder modelBuilder)
Purpose
- Captures the state of the EF Core model at the time of migration 20250306035117.
- Defines table schemas, columns, keys, indexes, and relationships for all domain entitiesโwith a special focus on the newly introduced
CrewEmployeejoin table.
โ๏ธ Dependencies & Technologies
| Technology | Version / Notes |
|---|---|
| .NET / C# | .NET 7+, C# 10+ |
| Entity Framework Core | EF Core 9.0.0 (SQL Server Proยญvider) |
| SQL Server | Relational database with โirbyโ schema |
| Tools | dotnet ef migrations add / update-database |
๐๏ธ Key Functional Areas
-
Model Annotations
modelBuilder.HasAnnotation("ProductVersion", "9.0.0")UseIdentityColumns()
-
Entity Definitions
- Tables like
AccountBalances,Asset,Employee, ... plus the newCrewEmployee.
- Tables like
-
Relationships
- Oneโtoโmany, manyโtoโmany join tables, inheritance (TPH), indexes, constraints.
-
Schema
- Default
irbyschema applied to all tables except some view models and ODS tables.
- Default
โ Changes Introduced: CrewEmployee Table
๐ Migration Name: AddCrewEmployeeTable
๐ฏ Goal: Introduce a manyโtoโmany mapping between Crew and Employee.
- Each Crew can have multiple Employees.
- Each Employee can belong to multiple Crews.
๐ Entity Mapping in BuildTargetModel
The BuildTargetModel(ModelBuilder modelBuilder) method uses a fluent API to recreate the entire EF Core model.
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// ... dozens of Entity() configurations ...
// -->>> Our new mapping appears here
modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEmployee", b =>
{
b.Property<Guid>("CrewId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("EmployeeId")
.HasColumnType("uniqueidentifier");
b.HasKey("CrewId", "EmployeeId");
b.HasIndex("EmployeeId");
b.ToTable("CrewEmployee", "irby");
});
// ... relationship wiring at the end ...
}
๐ CrewEmployee Table Definition
| Column | CLR Type | SQL Type | Constraint |
|---|---|---|---|
| CrewId | Guid |
uniqueidentifier |
Part of Primary Key, FK โ Crew.CrewId |
| EmployeeId | Guid |
uniqueidentifier |
Part of Primary Key, FK โ Employee.EmployeeId |
- Composite Primary Key: (
CrewId,EmployeeId) - Index: on
EmployeeIdfor faster lookups. - Schema:
irby - Table:
CrewEmployee
๐งฉ Relationships & Navigation Properties
At the bottom of BuildTargetModel, the foreign keys are wired:
modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEmployee", b =>
{
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();
});
Crewโ navigationCrew.CrewEmployees(collection of join records)Employeeโ navigationEmployee.CrewEmployees
๐ง Usage Examples & Code Snippets
1. Adding a CrewโEmployee Link
using var context = new IrbyContext();
// Suppose existing crewId and employeeId
var link = new CrewEmployee {
CrewId = crewId,
EmployeeId = employeeId
};
context.Set<CrewEmployee>().Add(link);
context.SaveChanges();
2. Querying All Employees in a Crew
var crewWithEmployees = context.Crews
.Include(c => c.CrewEmployees)
.ThenInclude(ce => ce.Employee)
.FirstOrDefault(c => c.CrewId == crewId);
foreach (var ce in crewWithEmployees.CrewEmployees)
{
Console.WriteLine(ce.Employee.DisplayName);
}
3. Removing an Employee from a Crew
var link = context.Set<CrewEmployee>()
.SingleOrDefault(ce => ce.CrewId == crewId && ce.EmployeeId == employeeId);
if (link != null) {
context.Remove(link);
context.SaveChanges();
}
๐ UML Diagram
classDiagram
CrewEmployee "1" -- "0..*" Crew : CrewId
CrewEmployee "1" -- "0..*" Employee : EmployeeId
Crew "1" -- "0..*" CrewEmployee : has
Employee "1" -- "0..*" CrewEmployee : belongs to
๐ How to Run the Migration
- Add the migration (already done):
dotnet ef migrations add AddCrewEmployeeTable - Apply the migration:
dotnet ef database update - Verify: Check
irby.CrewEmployeein your SQL Server Management Studio.
๐ Conclusion
- This Designer file is the snapshot of your EF Core model at migration 20250306035117.
- It fully describes all entities and relationshipsโparticularly the new
CrewEmployeemanyโtoโmany join. - No manual edits are required; EF Core regenerates it during migration scaffolding.
Feel free to reference this document when inspecting the database schema, troubleshooting migrations, or writing repository code around the Crew โ Employee relationship. ๐