📁 AddCostCodeColumnsToClassificationTable.Designer.cs

Auto-generated EF Core migration snapshot for AddCostCodeColumnsToClassificationTable
This file is part of the IrbyImaging.DbContext.Migrations namespace and houses the complete model snapshot after applying the migration.


📖 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Models
  5. UML Diagram
  6. Helper Methods & Utilities
  7. Error Handling & Return Types
  8. API Endpoints Overview
  9. Third‑party Integrations
  10. Sample Code Blocks
  11. Usage Examples
  12. Conclusion

1. Overview & Purpose

This .Designer.cs file is part of an Entity Framework Core migration named AddCostCodeColumnsToClassificationTable. It does not contain the Up() and Down() definitions (those live in the main migration file), but instead defines the post‑migration model snapshot via the BuildTargetModel method. EF Core uses this snapshot to:

  • Compare your current model against previous migrations.
  • Scaffold future migrations.
  • Maintain a source of truth for all tables, columns, keys, indexes, relationships, and types.

🔑 Key takeaway: Never manually edit designer snapshots. They are auto-generated whenever you run dotnet ef migrations add ... or Update-Database.


2. Dependencies & Technologies

Dependency Version/Notes
.NET / EF Core EF Core 9.0.0, SQL Server provider
ModelBuilder Microsoft.EntityFrameworkCore.Metadata
Migrations API Microsoft.EntityFrameworkCore.Migrations
Value Conversions Microsoft.EntityFrameworkCore.Storage.ValueConversion

3. Key Functional Areas

3.1 Migration Attributes

[DbContext(typeof(IrbyContext))]
[Migration("20250117204950_AddCostCodeColumnsToClassificationTable")]
partial class AddCostCodeColumnsToClassificationTable
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder) { ... }
}
  • DbContext attribute: Ties this migration to IrbyContext.
  • Migration attribute: Uses a timestamped identifier (20250117204950) & the name AddCostCodeColumnsToClassificationTable.

3.2 BuildTargetModel Method

  • Signature:
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    
  • Purpose: Recreates the full EF Core model (all tables/entities) at this point in time.
  • Behavior:
    1. Sets global annotations (e.g., product version).
    2. Configures each entity:
      • Properties (name, CLR type, SQL type, nullability).
      • Keys (HasKey).
      • Indexes (HasIndex).
      • Table mapping (ToTable).
      • Relationships (HasOne / WithMany).

3.3 New CostCode Columns

The primary goal of this migration is to add two new columns to the JobClassification table:

Column Name CLR Type SQL Type Description
CostCodeNumber int int Numeric cost code associated with the job.
CostCodeName string nvarchar(max) Human‑readable name/description of the code.

🔍 Snippet from BuildTargetModel:

modelBuilder.Entity("IrbyImaging.DomainClasses.JobClassification", b =>
{
    b.Property<Guid>("JobClassificationId").ValueGeneratedOnAdd().HasColumnType("uniqueidentifier");
    // ... existing columns ...
    b.Property<int>("CostCodeNumber").HasColumnType("int");           // NEW
    b.Property<string>("CostCodeName").HasColumnType("nvarchar(max)"); // NEW
    // ... rest of configuration ...
    b.ToTable("JobClassification", "irby");
});

These properties will now map to the underlying SQL columns, and EF Core will ensure data is preserved and migrations applied correctly.

3.4 Entity Snapshot Details

This snapshot includes all domain entities — over 120 of them! Below is just a summarized view:

Entity Table (Schema) Key Sample Properties
AccountBalances irby.AccountBalances AccountBalanceId (GUID) AccountingCode, Cost, Revenue, ManHours
Asset (base) irby.Asset Id (GUID) Category, SerialNumber, PurchaseDate
JobClassification irby.JobClassification JobClassificationId (GUID) Name, SAMReference, FringeAmount, CostCode*
Job irby.Job JobId (GUID) Name, JdeNumber, FieldOfficeId, BudgetApproved
Employee irby.Employee EmployeeId (GUID) FirstName, LastName, JdeNumber, DepartmentId
... ... ... ...

Note: Each entity is fully configured — indexes, relationships, discriminator columns (for TPH), and SQL types.


4. Data Models

While the full snapshot is enormous, here is how JobClassification now looks conceptually:

public class JobClassification
{
    public Guid JobClassificationId { get; set; }
    public Guid JobId              { get; set; }
    public string Name             { get; set; }
    public int ClassNumber         { get; set; }
    public decimal FringeAmount    { get; set; }
    
    // ✨ New cost code support:
    public int CostCodeNumber      { get; set; }
    public string CostCodeName     { get; set; }
    
    public byte[] ImageOCRContents { get; set; }
    public string ImageOCRText     { get; set; }
    
    // navigation:
    public Job Job                  { get; set; }
}

5. UML Diagram

Below is a PlantUML snippet showing the relationship between Job and JobClassification:

@startuml
entity "Job" as Job {
  * JobId : Guid <<PK>>
  --
  Name : string
  JdeNumber : string
  // ...
}

entity "JobClassification" as JC {
  * JobClassificationId : Guid <<PK>>
  --
  CostCodeNumber : int
  CostCodeName : string
  ClassNumber : int
  // ...
  JobId : Guid <<FK>>
}

Job ||--|{ JC : "Has Classifications"
@enduml

Job-Classification UML

Paste this code in a PlantUML‑enabled tool to render the diagram locally.


6. Helper Methods & Utilities

This designer file is auto‑generated and contains no custom utility or helper functions. All logic is expressed declaratively via ModelBuilder.


7. Error Handling & Return Types

  • Error Handling: None. EF Core builds the model declaratively; errors surface at design‑time or during migration application.
  • Return Types: void — the BuildTargetModel method configures the passed ModelBuilder.

8. API Endpoints Overview

❌ Not applicable
This file defines the data model, not any HTTP or web API logic.


9. Third‑party Integrations

  • Entity Framework Core: Primary ORM for .NET.
  • Microsoft SQL Server: Underlying relational database.
  • PlantUML (optional): For generating diagrams.

10. Sample Code Blocks

Running the Migration

# Generate a new migration
dotnet ef migrations add AddCostCodeColumnsToClassificationTable

# Apply to the database
dotnet ef database update

Verifying in C#

using (var ctx = new IrbyContext())
{
    var classification = new JobClassification
    {
        JobId = someJobId,
        Name = "Electrician",
        ClassNumber = 3,
        CostCodeNumber = 1001,         // new
        CostCodeName = "Electrical"   // new
    };
    ctx.JobClassifications.Add(classification);
    ctx.SaveChanges();
}

11. Usage Examples

  1. Query by Cost Code
    var codes = ctx.JobClassifications
                   .Where(jc => jc.CostCodeNumber == 1001)
                   .Select(jc => jc.CostCodeName)
                   .Distinct()
                   .ToList();
    
  2. Update Existing
    var jc = ctx.JobClassifications.Find(existingId);
    jc.CostCodeName = "Updated Name";
    ctx.SaveChanges();
    

12. Conclusion

✨ AddCostCodeColumnsToClassificationTable.Designer.cs is the EF Core model snapshot after introducing CostCodeNumber and CostCodeName to the JobClassification entity. It:

  • Ensures EF Core remembers the entire schema.
  • Drives future migrations by comparing old vs. new snapshots.
  • Should never be manually edited; treat it as read‑only.

🎉 With this migration applied, your application can capture and persist cost codes alongside job classifications, unlocking richer reporting and data integrity.