📑 Migration Documentation: AddMoreColumnsToClassAndCostCodes.Designer.cs

Auto‐generated Entity Framework Core migration snapshot for the AddMoreColumnsToClassAndCostCodes migration.


Table of Contents

  1. Overview & Purpose
  2. File Structure
  3. Dependencies & Technologies
  4. Key Functional Areas
  5. Model Snapshot: BuildTargetModel
  6. Entities Affected
  7. Relationships & Indexes
  8. Mermaid UML Diagram
  9. Applying & Rolling Back Migrations
  10. Usage Example
  11. Conclusion

1. Overview & Purpose

🔍 What is this file?
This file is the EF Core–generated snapshot for the migration named 20250115193119_AddMoreColumnsToClassAndCostCodes. Its role is to tell EF Core exactly how your database schema should look after the migration is applied.

📌 Why it exists

  • Tracks the state of your DbContext model at a given point in time.
  • Enables EF Core to compare future model changes against this snapshot and generate diffs.
  • Should not be edited manually—any changes to your domain classes trigger a new snapshot on the next migration.

2. File Structure

IrbyImaging.DbContext/
  Migrations/
    ├── 20250115193119_AddMoreColumnsToClassAndCostCodes.cs       // Up/Down logic
    └── 20250115193119_AddMoreColumnsToClassAndCostCodes.Designer.cs  // This snapshot

Inside the .Designer.cs:

  1. Usings & Namespace
  2. [DbContext] & [Migration] Attributes
  3. Partial Migration Class
  4. Override BuildTargetModel(ModelBuilder modelBuilder)

3. Dependencies & Technologies

Technology Version Purpose
.NET / C# 9.0 Runtime & language
Microsoft.EntityFrameworkCore 9.0 ORM and migrations framework
SQL Server relational Underlying database provider

4. Key Functional Areas

  1. Migration Decoration

    [DbContext(typeof(IrbyContext))]
    [Migration("20250115193119_AddMoreColumnsToClassAndCostCodes")]
    partial class AddMoreColumnsToClassAndCostCodes { … }
    
    • Links the snapshot to your IrbyContext and assigns a unique timestamp ID.
  2. Schema Snapshot

    • The BuildTargetModel method configures all entities, properties, keys, indexes, relationships as they should exist after this migration.
  3. Annotations & Conventions

    • Sets ProductVersion and MaxIdentifierLength.
    • Calls UseIdentityColumns for SQL Server–style IDENTITY support.

5. Model Snapshot: BuildTargetModel

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    #pragma warning disable 612, 618
    modelBuilder
        .HasAnnotation("ProductVersion", "9.0.0")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    // Enable IDENTITY columns for SQL Server
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // ► Definitions for every EntityType follow
    modelBuilder.Entity("IrbyImaging.DomainClasses.CostCode", b => {
        b.Property<Guid>("CostCodeId")
            .ValueGeneratedOnAdd()
            .HasColumnType("uniqueidentifier");
        b.Property<int>("CostCodeNumber").HasColumnType("int");
        b.Property<Guid>("JobId").HasColumnType("uniqueidentifier");
        b.Property<string>("Name").HasColumnType("nvarchar(max)");
        b.HasKey("CostCodeId");
        b.HasIndex("JobId");
        b.ToTable("CostCode", "irby");
    });

    // … all other entities are configured similarly …
    #pragma warning restore 612, 618
}
  • Each call to modelBuilder.Entity(...) defines an EntityType.
  • Within each, properties (b.Property<>()), keys (b.HasKey()), indexes (b.HasIndex()), and table mappings (b.ToTable()) are declared.

6. Entities Affected

Since this migration’s name refers to Class and CostCodes, the two primary DomainClasses of interest are:

Entity Table (Schema) Key Column Main Properties
CostCode irby.CostCode CostCodeId CostCodeNumber, JobId, Name
EquipmentClass irby.EquipmentClass EquipmentClassId ClassId, Name

CostCode Entity

Column Type Notes
CostCodeId uniqueidentifier PK, generated on add
CostCodeNumber int new or existing business code
JobId uniqueidentifier FK to Job entity
Name nvarchar(max) descriptive name of cost code

EquipmentClass Entity

Column Type Notes
EquipmentClassId uniqueidentifier PK, generated on add
ClassId int integer classification code
Name nvarchar(max) human‐readable class name

ℹ️ If your Up()/Down() migration adds columns, the .Designer.cs snapshot will include them here automatically.


7. Relationships & Indexes

  • CostCode ⇄ Job

    • b.HasOne("Job").WithMany().HasForeignKey("JobId")
    • Enforced at DB level with index on JobId.
  • EquipmentClass

    • No direct FK relationships in this snapshot—used by EquipmentType.
// Example: CostCode → Job
b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
 .WithMany()  // no inverse navigation
 .HasForeignKey("JobId")
 .OnDelete(DeleteBehavior.Cascade)
 .IsRequired();

8. Mermaid UML Diagram

classDiagram
    CostCode --> Job : JobId
    EquipmentClass : +Guid EquipmentClassId
    EquipmentClass : +int ClassId
    EquipmentClass : +string Name
    Job : +Guid JobId
    Job : +string Name
  • Arrows indicate foreign‐key references.
  • Classes list their key properties.

9. Applying & Rolling Back Migrations

# To apply this migration (and all pending):
dotnet ef database update

# To roll back one migration:
dotnet ef database update 20250115193118_PreviousMigration
  • EF Core uses the .Designer.cs to compute the target snapshot.
  • The accompanying .cs (without “Designer”) contains the Up() and Down() SQL or fluent API commands.

10. Usage Example

After coding new properties in your domain classes (e.g., adding ClassId to EquipmentClass), you would:

# 1. Scaffold new migration
dotnet ef migrations add AddMoreColumnsToClassAndCostCodes

# 2. Review generated
#    - Up(): AlterTable AddColumn(...)
#    - .Designer.cs: full snapshot updated

# 3. Apply to database
dotnet ef database update

11. Conclusion

✅ Summary

  • This .Designer.cs file is a complete snapshot of your EF Core model after the "AddMoreColumnsToClassAndCostCodes" migration.
  • It ensures consistency between your C# domain classes and the underlying SQL schema.

🛑 Do Not modify by hand—rely on EF Core’s CLI or Package Manager integration to keep this in sync.

🔗 Further Reading


Generated with ❤️ to help you navigate your EF Core migration snapshot!