πŸ“„ Documentation: 20240130134140_MoreUpdatesToJobTable.Designer.cs


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. EF Core Migrations at a Glance
  3. File Structure & Attributes
  4. The BuildTargetModel Method
  5. Data Models & Entity Mappings
    • 5.1. Key Entities
    • 5.2. Table & Schema Mapping
  6. πŸ”§ Key Changes to Job Table
  7. Dependencies & Technologies
  8. Usage Examples & CLI Commands
  9. UML Diagram (Simplified)
  10. Conclusion 🎯

1. Overview & Purpose

This auto-generated designer file is part of an Entity Framework Core (EF Core) migration named MoreUpdatesToJobTable. It contains a snapshot of the target data model after the migration has been applied. EF Core uses this snapshot to:

  • Compare your current model to the database schema.
  • Generate SQL commands for future migrations.
  • Ensure consistency across development, CI/CD pipelines, and production.

File: IrbyImaging.DbContext/Migrations/20240130134140_MoreUpdatesToJobTable.Designer.cs


2. EF Core Migrations at a Glance

  • πŸ”„ Migrations
    Represent version-controlled schema changes.
  • πŸ“‹ Migration Class
    Defines Up() and Down() methods to apply or roll back changes.
  • πŸ“ Designer File
    Contains the BuildTargetModel(ModelBuilder) method β€” a complete model snapshot.
  • βš™οΈ ModelBuilder
    Fluent API for configuring tables, columns, keys, relationships, indexes, etc.

3. File Structure & Attributes

namespace IrbyImaging.DbContext.Migrations
{
  [DbContext(typeof(IrbyContext))]
  [Migration("20240130134140_MoreUpdatesToJobTable")]
  partial class MoreUpdatesToJobTable
  {
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
      // … fluent mapping of every entity …
    }
  }
}
  • [DbContext] associates this migration with IrbyContext.
  • [Migration("...")] assigns a timestamped identifier.
  • BuildTargetModel is auto-generated β€” do not modify it manually.

4. The BuildTargetModel Method

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
  #pragma warning disable 612, 618

  modelBuilder
    .HasAnnotation("ProductVersion", "7.0.7")
    .HasAnnotation("Relational:MaxIdentifierLength", 128);
  SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

  //  ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– 
  //  Entity configurations below:
  //    β€’ Properties (Column types, constraints)  
  //    β€’ Keys & Indexes  
  //    β€’ Relationships (HasOne, WithMany)  
  //    β€’ Table & Schema mapping  
  //  –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
}

Highlights

  • Sets provider annotations (SQL Server 7.0.7).
  • Enables Identity columns for primary keys.
  • Iterates over all entities in IrbyImaging.DomainClasses.

5. Data Models & Entity Mappings

5.1. Key Entities

There are ~90 entities mapped in this model. We’ll highlight a few central ones:

Entity Class Table Name Schema
Job Job irby
FieldOffice FieldOffice irby
Employee Employee irby
Asset (TPH base) Asset irby
DocumentImage DocumentImage irby
… and many more domain-specific types

5.2. Table & Schema Mapping

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

  // Column mappings …
});
  • .ToTable() β€” maps an entity to a specific table and schema.
  • .HasKey() β€” defines the primary key.
  • Additional calls configure columns, indexes, and relationships.

6. πŸ”§ Key Changes to Job Table

The primary purpose of this migration is captured by updates to the Job entity:

modelBuilder.Entity("IrbyImaging.DomainClasses.Job", b =>
{
  b.Property<Guid>("JobId")
    .ValueGeneratedOnAdd()
    .HasColumnType("uniqueidentifier");
  b.Property<string>("Name")
    .HasColumnType("nvarchar(max)");
  b.Property<string>("JdeNumber")
    .HasColumnType("nvarchar(450)");
  b.Property<Guid?>("FieldOfficeId")
    .HasColumnType("uniqueidentifier");
  // … other properties …

  // Index on FieldOfficeId
  b.HasIndex("FieldOfficeId");

  // Unique index on JdeNumber (if not null)
  b.HasIndex("JdeNumber")
    .IsUnique()
    .HasFilter("[JdeNumber] IS NOT NULL");

  // FK Relationship
  b.HasOne("IrbyImaging.DomainClasses.FieldOffice", "FieldOffice")
    .WithMany("Jobs")
    .HasForeignKey("FieldOfficeId");
});

Summary of Changes

  • New/Modified Columns:
    • JdeNumber configured as nvarchar(450) for uniqueness.
    • Potential addition of new GUID FKs (ManagerId, ProjectManagerId, etc.).
  • Indexes:
    • Unique index on JdeNumber.
    • Standard index on FieldOfficeId for performance in joins.
  • Relationships:
    • Linking Job β†’ FieldOffice (1 FieldOffice has many Jobs).

7. Dependencies & Technologies

Item Version / Notes
.NET SDK 7.0.x
EF Core 7.0.7
Database Provider Microsoft SQL Server
C# Language Version 10.0 (Top-level statements, nullable disabled)
Schema & Conventions TPH (Table‑Per‑Hierarchy) for inheritance on Asset

8. Usage Examples & CLI Commands

  1. Add a new migration
    dotnet ef migrations add MoreUpdatesToJobTable
    
  2. Update your database
    dotnet ef database update MoreUpdatesToJobTable
    
  3. Rollback to previous migration
    dotnet ef database update <PreviousMigrationName>
    
  4. Register context in Startup
    services.AddDbContext<IrbyContext>(options =>
        options.UseSqlServer(configuration.GetConnectionString("IrbyDb")));
    

9. UML Diagram (Simplified)

Below is a simplified PlantUML snippet illustrating the core relationship between Job and FieldOffice:

@startuml
class Job {
  - Guid JobId
  - string Name
  - string JdeNumber
  - Guid? FieldOfficeId
}

class FieldOffice {
  - Guid Id
  - string Name
}

FieldOffice "1" -- "0..*" Job : manages >
@enduml

You can paste the above into any PlantUML renderer to visualize the relationship.


10. Conclusion 🎯

This designer file is a critical piece of your EF Core migration pipeline. It:

  • Captures the complete shape of your data model at this migration point.
  • Ensures EF Core can diff future changes against the last applied schema.
  • Provides fluent mappings for every property, key, index, and relationship.

By understanding its structure and content, developers can better:

  • Troubleshoot schema mismatches.
  • Extend migrations safely.
  • Maintain a clear history of database changes alongside domain model evolution.

Happy coding! πŸš€