πŸ“– Documentation: UpdateCrewEmployeeTime.Designer.cs

Path: IrbyImaging.DbContext/Migrations/20250317161629_UpdateCrewEmployeeTime.Designer.cs
Auto-generated EF Core Migration Designer – DO NOT EDIT this file directly.


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Migration Class: UpdateCrewEmployeeTime
  3. BuildTargetModel Method
  4. Key Entities Affected πŸ—„οΈ
  5. Dependencies & Technologies βš™οΈ
  6. Sample Code Snippets 🧩
  7. Usage Examples πŸš€
  8. Simplified UML Diagram πŸ“Š
  9. Conclusion

1. Overview & Purpose

This Designer file is part of an Entity Framework Core migration named 20250317161629_UpdateCrewEmployeeTime. When you run dotnet ef migrations add or dotnet ef database update, EF Core uses this snapshot to know what your database model looked like at the time of this migration.

  • Auto-generated by the EF Core tools.
  • Provides a model snapshot of all entities and their relationships.
  • BuildTargetModel recreates the schema in C# so EF can diff and apply changes.

⚠️ Never modify this file manually. Use migrations or update your domain classes instead.


2. Migration Class: UpdateCrewEmployeeTime

namespace IrbyImaging.DbContext.Migrations
{
    [DbContext(typeof(IrbyContext))]
    [Migration("20250317161629_UpdateCrewEmployeeTime")]
    partial class UpdateCrewEmployeeTime
    {
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            // ... auto-generated entity configurations ...
        }
    }
}
  • [DbContext(typeof(IrbyContext))]
    Binds this migration to the IrbyContext EF Core context.
  • [Migration("20250317161629_UpdateCrewEmployeeTime")]
    Unique timestamped identifier used by EF Core to order and apply migrations.
  • BuildTargetModel(ModelBuilder)
    Defines the complete model snapshot at this migration state.

3. BuildTargetModel Method

The heart of the designer file is the BuildTargetModel method:

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    modelBuilder
        .HasAnnotation("ProductVersion", "9.0.0")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // Entity definitions follow, e.g.:
    modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEmployee", b =>
    {
        b.Property<Guid>("CrewId")
         .HasColumnType("uniqueidentifier");

        b.Property<Guid>("EmployeeId")
         .HasColumnType("uniqueidentifier");

        b.Property<DateTime?>("StartTime")
         .HasColumnType("datetime2");

        b.HasKey("CrewId", "EmployeeId");
        b.ToTable("CrewEmployee", "irby");
    });

    // ... thousands of lines of other entity mappings ...
}

Highlights:

  • Annotations set global metadata (ProductVersion, SQL Server specifics).
  • UseIdentityColumns: Configures auto-increment/identity behavior on integer keys.
  • modelBuilder.Entity(...): Configures each Domain class:
    • Properties (Property<T>)
    • Keys (HasKey)
    • Relationships (HasOne, WithMany, HasForeignKey)
    • Table & Schema (ToTable("...", "irby"))

4. Key Entities Affected πŸ—„οΈ

While the snapshot contains all entities, this migration focuses on crew & time tables:

Entity Schema.Table Notes
Crew irby.Crew Groups of employees on a job
CrewEmployee irby.CrewEmployee Junction table (Crew ↔ Employee)
EmployeeTimesheet irby.EmployeeTimesheet Timesheet per employee per crew session
WorkEntry irby.WorkEntry Individual work record on a timesheet
FieldTimesheet irby.FieldTimesheet High-level timesheet covering crew crews
EquipmentTimesheet irby.EquipmentTimesheet Equipment usage logs

These entities include a StartTime column in CrewEmployee, likely the reason for migration:

b.Property<DateTime?>("StartTime")
 .HasColumnType("datetime2");

5. Dependencies & Technologies βš™οΈ

  • .NET 7/8/9 (C# 11+)
  • Entity Framework Core 9.0.0
  • SQL Server as relational provider
  • IrbyImaging.DbContext – custom EF Core context

6. Sample Code Snippets 🧩

6.1 Inspecting CrewEmployee Mapping

modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEmployee", b =>
{
    b.Property<Guid>("CrewId")
     .HasColumnType("uniqueidentifier");

    b.Property<Guid>("EmployeeId")
     .HasColumnType("uniqueidentifier");

    b.Property<DateTime?>("StartTime")
     .HasColumnType("datetime2");

    b.HasKey("CrewId", "EmployeeId");
    b.ToTable("CrewEmployee", "irby");
});

6.2 Relationship Example (Crew ↔ CrewEmployee)

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();
});

7. Usage Examples πŸš€

  1. Create Migration
    dotnet ef migrations add UpdateCrewEmployeeTime
  2. Apply to Database
    dotnet ef database update 20250317161629_UpdateCrewEmployeeTime
  3. Revert
    dotnet ef database update 20250317161629_PreviousMigration

EF Core uses the Designer file to generate SQL DDL under the hood.


8. Simplified UML Diagram πŸ“Š

 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚  Crew   β”‚1───────│ CrewEmployee      β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚ (PK: CrewId, Emp)β”‚
      β–²              β”‚ StartTime: datetime2? 
      β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚                       β–²
      β”‚                       β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚ Employee     β”‚1──────│ EmployeeTimesheet β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β–²
                           β”‚
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚ WorkEntryβ”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Crew ↔ CrewEmployee ↔ Employee
  • EmployeeTimesheet and WorkEntry link on timesheet details.

9. Conclusion

This auto-generated EF Core migration designer file captures a snapshot of your entire database model at the moment you added the UpdateCrewEmployeeTime migration. Its primary role is to allow EF Core to❗:

  • Understand how tables and columns are structured.
  • Compute the Ξ” (changes) between migrations.
  • Generate the appropriate SQL scripts for up/ down.

πŸ”„ When you modify your domain classes (e.g., adding StartTime on CrewEmployee), re-run dotnet ef migrations add … to update both the migration and its designer.


Happy Coding! πŸš€