π Migration Documentation: 20250317160033_UpdateCrewModels.Designer.cs
Module:
IrbyImaging.DbContext/Migrations/20250317160033_UpdateCrewModels.Designer.cs
Context: Entity Framework Core (EF Core) auto-generated migration designer
Purpose: Defines the EF Core model snapshot after applying theUpdateCrewModelsmigration
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Class:
UpdateCrewModels - Key Method:
BuildTargetModel - Entities Affected by This Migration
- Mermaid UML Diagram
- How EF Core Migrations Work
- Usage Examples
- Conclusion
π Overview & Purpose
This Designer file is an auto-generated snapshot of the Entity Framework Core model after applying the UpdateCrewModels migration. It should not be manually edited. EF Core uses it to:
- Track the current shape of your domain entities and relationships
- Reconcile differences when creating new migrations
- Rebuild the database schema accurately during
dotnet ef database update
Migration Name: 20250317160033_UpdateCrewModels
DbContext: IrbyContext
π οΈ Dependencies & Technologies
| Package / Namespace | Purpose |
|---|---|
Microsoft.EntityFrameworkCore |
Core EF functionality |
Microsoft.EntityFrameworkCore.Migrations |
Migration APIs |
Microsoft.EntityFrameworkCore.Metadata |
Model metadata (entities, keys, relationships) |
Microsoft.EntityFrameworkCore.Infrastructure |
Design-time infrastructure |
Microsoft.EntityFrameworkCore.Storage.ValueConversion |
Value conversion mapping |
π§© Migration Class: UpdateCrewModels
[DbContext(typeof(IrbyContext))]
[Migration("20250317160033_UpdateCrewModels")]
partial class UpdateCrewModels
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// ... auto-generated model snapshot
}
}
-
Decorators
[DbContext(typeof(IrbyContext))]β Associates this migration withIrbyContext.[Migration("20250317160033_UpdateCrewModels")]β Uniquely identifies this migration by timestamp and name.
-
Partial Class
EF splits a migration into two partial files:- Operations (Up/Down)
- Designer (Model snapshot) β this file.
π Key Method: BuildTargetModel
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// Entity configurations follow...
}
modelBuildersets up all entity types, properties, keys, indexes, and relationships as they exist after this migration.- Annotations record EF Core and database provider metadata.
- UseIdentityColumns ensures SQL Server identity configuration.
π Entities Affected by This Migration
Although the designer lists all entities, the
UpdateCrewModelsmigration focuses on crew-related tables. Below are the relevant excerpts:
1. Crew
| Property | Type | Comment |
|---|---|---|
CrewId |
Guid |
Primary Key |
CrewName |
string |
Name of the crew |
CreatedBy, CreatedDate |
audit columns | Tracking metadata |
FieldTimesheetTimesheetId |
Guid? |
FK β FieldTimesheet.TimesheetId |
JobId |
Guid |
FK β Job.JobId |
Snippet:
modelBuilder.Entity("IrbyImaging.DomainClasses.Crew", b =>
{
b.Property<Guid>("CrewId").ValueGeneratedOnAdd();
b.Property<string>("CrewName");
b.Property<Guid?>("FieldTimesheetTimesheetId");
b.Property<Guid>("JobId");
b.HasKey("CrewId");
b.HasIndex("FieldTimesheetTimesheetId");
b.HasIndex("JobId");
b.ToTable("Crew", "irby");
});
2. CrewEmployee
| Property | Type | Comment |
|---|---|---|
CrewId |
Guid |
PK + FK β Crew.CrewId |
EmployeeId |
Guid |
PK + FK β Employee.EmployeeId |
CostCodeId |
Guid? |
FK β CostCode.CostCodeId (optional) |
JobClassificationId |
Guid? |
FK β JobClassification.JobClassificationId |
PerDiemRate |
decimal? |
Billing specification |
StartTime |
TimeSpan? |
Timesheet start |
| Audit & Soft-Delete | various | IsDeleted, CreatedBy, CreatedDate |
Composite PK: (CrewId, EmployeeId)
Snippet:
modelBuilder.Entity("CrewEmployee", b =>
{
b.HasKey("CrewId", "EmployeeId");
b.HasIndex("CostCodeId");
b.HasIndex("EmployeeId");
b.HasIndex("JobClassificationId");
b.ToTable("CrewEmployee", "irby");
});
3. CrewEquipment
| Property | Type | Comment |
|---|---|---|
CrewEquipmentId |
Guid |
Primary Key |
CrewId |
Guid |
FK β Crew.CrewId |
EquipmentId |
Guid |
FK β Equipment.EquipmentId |
CostCodeId |
Guid? |
FK β CostCode.CostCodeId (optional) |
JobId |
Guid |
FK β Job.JobId |
WorkedHours |
decimal? |
Hours recorded |
| Audit & Soft-Delete | various | IsDeleted, CreatedBy, CreatedDate |
Snippet:
modelBuilder.Entity("CrewEquipment", b =>
{
b.HasKey("CrewEquipmentId");
b.HasIndex("CostCodeId");
b.HasIndex("CrewId");
b.HasIndex("EquipmentId");
b.HasIndex("JobId");
b.ToTable("CrewEquipment", "irby");
});
π·οΈ Mermaid UML Diagram
classDiagram
Crew <|-- CrewEmployee : contains
Crew <|-- CrewEquipment
CrewEmployee --> Employee : references
CrewEmployee --> CostCode : references
CrewEmployee --> JobClassification : references
CrewEquipment --> Equipment : references
CrewEquipment --> CostCode : references
class Crew {
+Guid CrewId
+string CrewName
+Guid? FieldTimesheetTimesheetId
+Guid JobId
}
class CrewEmployee {
+Guid CrewId
+Guid EmployeeId
+Guid? CostCodeId
+Guid? JobClassificationId
+decimal? PerDiemRate
+TimeSpan? StartTime
}
class CrewEquipment {
+Guid CrewEquipmentId
+Guid CrewId
+Guid EquipmentId
+Guid? CostCodeId
+Guid JobId
+decimal? WorkedHours
}
βοΈ How EF Core Migrations Work
- Scaffold:
dotnet ef migrations add UpdateCrewModels - Designer Snapshot: EF generates this fileβs
BuildTargetModelto reflect the entire model state. - Operations: Another partial class defines
Up()/Down()(schema changes). - Apply:
dotnet ef database updateuses both files to update the database.
π§ Usage Examples
Generating a Migration
dotnet ef migrations add UpdateCrewModels \
--context IrbyContext \
--output-dir IrbyImaging.DbContext/Migrations
Applying Migrations
dotnet ef database update --context IrbyContext
Rolling Back
dotnet ef database update 20250317160032_PreviousMigration
π― Conclusion
- This Designer file is a read-only snapshot of your EF Core model after the
UpdateCrewModelsmigration. - It contains the full mapping of entities, properties, keys, indexes, and relationshipsβwith special focus on Crew, CrewEmployee, and CrewEquipment tables.
- Understanding its structure ensures you can confidently generate, apply, and troubleshoot migrations in your IrbyImaging application.
Happy coding! π οΈποΈ