πŸš€ 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 the UpdateCrewModels migration


πŸ“‹ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Migration Class: UpdateCrewModels
  4. Key Method: BuildTargetModel
  5. Entities Affected by This Migration
  6. Mermaid UML Diagram
  7. How EF Core Migrations Work
  8. Usage Examples
  9. 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 with IrbyContext.
    • [Migration("20250317160033_UpdateCrewModels")] β€” Uniquely identifies this migration by timestamp and name.
  • Partial Class
    EF splits a migration into two partial files:

    1. Operations (Up/Down)
    2. 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...
}
  • modelBuilder sets 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 UpdateCrewModels migration 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

  1. Scaffold: dotnet ef migrations add UpdateCrewModels
  2. Designer Snapshot: EF generates this file’s BuildTargetModel to reflect the entire model state.
  3. Operations: Another partial class defines Up()/Down() (schema changes).
  4. Apply: dotnet ef database update uses 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 UpdateCrewModels migration.
  • 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! πŸ› οΈπŸ—„οΈ