📑 AddJobColumnToClassificationTable.Designer.cs Documentation


📚 Table of Contents

  1. Overview & Purpose
  2. Context: EF Core Migrations
  3. Key Functional Area: BuildTargetModel
    3.1 Model Annotations & Conventions
    3.2 Use of Identity Columns
  4. Entity Mappings & Highlight: JobClassification
    4.1 JobClassification Table Schema
    4.2 Foreign‑Key Relationship to Job
  5. Other Domain Entities (at a Glance)
  6. Dependencies & Technologies
  7. How to Use This Migration
  8. UML Diagram: Job ↔ JobClassification
  9. Conclusion

1. Overview & Purpose

File: AddJobColumnToClassificationTable.Designer.cs
Namespace: IrbyImaging.DbContext.Migrations
Migration: 20250116171432_AddJobColumnToClassificationTable

This auto‑generated designer file is part of an Entity Framework Core migration that adds a JobId column and foreign‑key relationship to the JobClassification table. It also captures the full model snapshot (BuildTargetModel) so EF Core can compare schema changes and generate appropriate SQL.


2. Context: EF Core Migrations

EF Core Migrations maintain an up-to-date database schema in sync with your C# domain classes:

  • Migration Attributes

    • [DbContext(typeof(IrbyContext))] : Targets the IrbyContext.
    • [Migration("20250116171432_AddJobColumnToClassificationTable")] : Unique timestamp + descriptive name.
  • Designer File

    • Contains BuildTargetModel(ModelBuilder modelBuilder)
    • Captures the full entity model snapshot after this migration is applied.

3. Key Functional Area: BuildTargetModel

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

    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // … Entity configurations follow …
    #pragma warning restore 612, 618
}

3.1 Model Annotations & Conventions

Annotation Purpose
ProductVersion = "9.0.0" EF Core version used for migration generation
Relational:MaxIdentifierLength = 128 SQL Server max length for identifiers (tables, columns)

3.2 Use of Identity Columns

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

Applies SQL Server's Identity strategy for auto‑incrementing primary keys (e.g. INT IDENTITY).


4. Entity Mappings & Highlight: JobClassification

The migration focuses on the JobClassification entity by adding:

  • JobId foreign‑key column (type uniqueidentifier)
  • An index on JobId
  • A cascade delete relationship to Job

4.1 JobClassification Table Schema

Property CLR Type SQL Type Notes
JobClassificationId Guid uniqueidentifier Primary key, generated on add
ClassNumber int int Classification code
City string nvarchar(max) Location
County string nvarchar(max) Location
FringeAmount decimal decimal(18,2) Fringe amount
ImageOCRContents byte[] varbinary(max) OCR image data
ImageOCRText string nvarchar(max) OCR extracted text
JobId Guid uniqueidentifier New FK column
modelBuilder.Entity("IrbyImaging.DomainClasses.JobClassification", b =>
{
    b.Property<Guid>("JobClassificationId")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");

    // … other properties …

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

    b.HasKey("JobClassificationId");
    b.HasIndex("JobId");
    b.ToTable("JobClassification", "irby");
});

4.2 Foreign‑Key Relationship to Job

modelBuilder.Entity("IrbyImaging.DomainClasses.JobClassification", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
     .WithMany()               // No navigation back from JobClassification
     .HasForeignKey("JobId")
     .OnDelete(DeleteBehavior.Cascade)
     .IsRequired();
});
  • Cascade Delete: Deleting a Job will delete its JobClassification rows.
  • Index on JobId for performance.

5. Other Domain Entities (at a Glance)

Beyond JobClassification, over 100 domain classes are mapped. Here’s a snapshot:

Entity Name Table Schema Notes
AccountBalances irby.AccountBalances Account balance reporting
Asset (TPH) irby.Asset Inheritance via Discriminator for various assets
Employee irby.Employee Staff directory with unique JdeNumber
Job irby.Job Central to many relationships (employees, POs)
FieldOffice irby.FieldOffice Office locations with staff assignments
PurchaseOrder irby.PurchaseOrder Linked to Job
WorkOrder irby.WorkOrder Equipment maintenance tasks
…and many more…

All entities include configurations for keys, indexes, table schemas, and relationships. Refer to the full file for details.


6. Dependencies & Technologies

  • .NET 7 / EF Core 9.0.0
  • SQL Server (relational provider, Identity columns)
  • Auto‑generated by dotnet ef migrations add

7. How to Use This Migration

  1. Add Migration
    dotnet ef migrations add AddJobColumnToClassificationTable
    
  2. Update Database
    dotnet ef database update
    
  3. Verify Changes
    • Check JobClassification table structure in your SQL Server.
    • Confirm JobId foreign key and cascade behavior.

8. UML Diagram: Job ↔ JobClassification

classDiagram
    class Job {
      +Guid JobId
      +string Name
      +...
    }

    class JobClassification {
      +Guid JobClassificationId
      +int ClassNumber
      +Guid JobId
      +...
    }

    Job "1" --> "*" JobClassification : HasMany
  • 1: A single Job can have many JobClassification records.
  • ★ Cascade delete keeps referential integrity.

9. Conclusion

This designer file captures the model snapshot after the AddJobColumnToClassificationTable migration. It ensures that:

  • JobClassification has a new, indexed JobId column.
  • Proper relationships and cascade rules are in place.
  • The rest of the domain model remains consistent for EF Core to track future changes.

🎉 You’re now equipped to apply, review, and extend this migration in your IrbyImaging solution!