📄 20250306183744_AddCrewEquipmentTable.Designer.cs Documentation


Table of Contents

  1. Overview & Purpose
  2. EF Core Migrations Context
  3. Designer File Structure
  4. Key Entity: CrewEquipment
  5. Relationship Mapping
  6. Model Snapshot & Annotations
  7. Using the Migration
  8. UML Diagram
  9. Dependencies & Technologies
  10. Conclusion

1. Overview & Purpose

File

IrbyImaging.DbContext/Migrations/20250306183744_AddCrewEquipmentTable.Designer.cs

Purpose
This is an auto‑generated Entity Framework Core designer file for the migration AddCrewEquipmentTable. It contains the model snapshot (via BuildTargetModel) representing the entire database schema after applying the migration that adds the new CrewEquipment table into the irby schema.

  • đŸ› ïž Role: Captures entity mappings, keys, indexes, relationships.
  • 📊 Scope: All domain entities up to this migration.
  • ✔ Benefit: Enables EF Core to diff, apply, or roll back schema changes consistently.

2. EF Core Migrations Context

When you scaffold a migration with EF Core, two files are produced:

Migrations/
├── 
_PreviousMigration.cs
├── 
_PreviousMigration.Designer.cs    ← Snapshot before new changes  
├── 20250306183744_AddCrewEquipmentTable.cs       ← Up/Down methods  
└── 20250306183744_AddCrewEquipmentTable.Designer.cs ← Model snapshot after changes
  • *.cs
    • Implements Up() / Down()—the DDL to modify your database.
  • *.Designer.cs
    • Implements BuildTargetModel(ModelBuilder)—a snapshot of your EF Core model.

3. Designer File Structure

// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace IrbyImaging.DbContext.Migrations
{
  [DbContext(typeof(IrbyContext))]
  [Migration("20250306183744_AddCrewEquipmentTable")]
  partial class AddCrewEquipmentTable
  {
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
      #pragma warning disable 612, 618

      // Global annotations
      modelBuilder
        .HasAnnotation("ProductVersion", "9.0.0")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

      // Configure identity columns for SQL Server
      SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

      // 
 dozens of modelBuilder.Entity(...) calls 


      // Our new entity mapping
      modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEquipment", b => { /* 
 */ });

      #pragma warning restore 612, 618
    }
  }
}

🔑 Key Sections

Section Description
Annotations ProductVersion, MaxIdentifierLength, etc.
Identity Columns Setup UseIdentityColumns for SQL Server ID generation
Entity Mappings Blocks of modelBuilder.Entity(...) for each class

4. Key Entity: CrewEquipment

This migration adds the CrewEquipment entity: a join table linking Crew, Equipment, and Job with audit and soft‑delete support.

Property Type Details
CrewEquipmentId Guid PK, generated on add
CreatedBy string Username who created the record
CreatedDate DateTime Timestamp of creation
CrewId Guid FK → Crew table
EquipmentId Guid FK → Equipment table
JobId Guid FK → Job table
IsDeleted bool Soft‑delete flag (logical deletion)

Mapping Snippet

modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEquipment", b =>
{
  b.ToTable("CrewEquipment", "irby");

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

  b.Property<string>("CreatedBy")
    .HasColumnType("nvarchar(max)");

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

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

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

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

  b.Property<bool>("IsDeleted")
    .HasColumnType("bit");

  // Primary Key
  b.HasKey("CrewEquipmentId");

  // Indexes for foreign keys
  b.HasIndex("CrewId");
  b.HasIndex("EquipmentId");
  b.HasIndex("JobId");
});

5. Relationship Mapping

modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEquipment", b =>
{
  // One Crew → Many CrewEquipment
  b.HasOne("IrbyImaging.DomainClasses.Crew", "Crew")
   .WithMany("CrewEquipment")
   .HasForeignKey("CrewId")
   .OnDelete(DeleteBehavior.Restrict)
   .IsRequired();

  // One Equipment → Many CrewEquipment
  b.HasOne("IrbyImaging.DomainClasses.Equipment", "Equipment")
   .WithMany()
   .HasForeignKey("EquipmentId")
   .OnDelete(DeleteBehavior.Restrict)
   .IsRequired();

  // One Job → Many CrewEquipment
  b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
   .WithMany()
   .HasForeignKey("JobId")
   .OnDelete(DeleteBehavior.Restrict)
   .IsRequired();
});
  • đŸȘąÂ Crew ← CrewEquipment → Equipment
  • đŸȘąÂ CrewEquipment → Job

6. Model Snapshot & Annotations

At the top of BuildTargetModel, you’ll see global annotations:

modelBuilder
  .HasAnnotation("ProductVersion", "9.0.0")
  .HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
  • ProductVersion: EF Core 9.0.0
  • MaxIdentifierLength: 128 (SQL Server default)
  • UseIdentityColumns: Enables IDENTITY on key columns

7. Using the Migration

  1. Add Migration
    dotnet ef migrations add AddCrewEquipmentTable
    
  2. Apply to Database
    dotnet ef database update
    
  3. Verify
    • Confirm presence of irby.CrewEquipment table
    • Inspect foreign keys and indexes

8. UML Diagram

erDiagram
  CREW ||--o{ CREW_EQUIPMENT : has
  EQUIPMENT ||--o{ CREW_EQUIPMENT : uses
  JOB ||--o{ CREW_EQUIPMENT : assigned_to

  CREW {
    Guid CrewId PK
    string CrewName
    ...
  }

  EQUIPMENT {
    Guid EquipmentId PK
    string DisplayName
    ...
  }

  JOB {
    Guid JobId PK
    string Name
    ...
  }

  CREW_EQUIPMENT {
    Guid CrewEquipmentId PK
    Guid CrewId FK
    Guid EquipmentId FK
    Guid JobId FK
    DateTime CreatedDate
    bool IsDeleted
  }

9. Dependencies & Technologies

Technology Version
.NET SDK ≄ 7.0
EF Core 9.0.0
SQL Server Engine 2016+
C# Language 10.0+

10. Conclusion

This Designer file is the EF Core snapshot after applying the AddCrewEquipmentTable migration. It ensures that EF Core knows precisely how to build or rebuild your database schema at this point in time—complete with entity definitions, foreign keys, indexes, and global annotations. 🚀