📦 Migration: 20240130142012_MoreUpdatesToJobTable2.Designer.cs

Auto-generated EF Core migration snapshot for IrbyImaging.DbContext
Builds the complete target model after applying the MoreUpdatesToJobTable2 migration.


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Migration Attributes & Structure
  4. BuildTargetModel Method
  5. Entity Configurations (Highlights)
  6. Key Changes in Job Table
  7. Relationships & Navigations
  8. UML Class Diagram (Excerpt)
  9. Sample Usage & Commands
  10. Conclusion

1. Overview & Purpose

This designer file is part of an Entity Framework Core migration (MoreUpdatesToJobTable2). Its sole responsibility is to define the target database schema in code so that EF Core can:

  • Compare the current database state against this snapshot
  • Generate SQL to apply or roll back changes
  • Maintain a history of schema versions

🚀 Intended Use: When running dotnet ef database update, EF Core reads this snapshot to know exactly how to scaffold or migrate your SQL Server database.


2. Dependencies & Technologies

  • .NET 7 / C#
  • Entity Framework Core 7 (Microsoft.EntityFrameworkCore)
  • SQL Server Provider (Microsoft.EntityFrameworkCore.SqlServer)
  • Value Conversions (Microsoft.EntityFrameworkCore.Storage.ValueConversion)

3. Migration Attributes & Structure

[DbContext(typeof(IrbyContext))]
[Migration("20240130142012_MoreUpdatesToJobTable2")]
partial class MoreUpdatesToJobTable2 { … }
  • DbContext Attribute binds this migration to IrbyContext.
  • Migration Attribute names the snapshot: 20240130142012_MoreUpdatesToJobTable2.
  • The heart of the file is BuildTargetModel(ModelBuilder modelBuilder).

4. BuildTargetModel Method

This method configures every table, column, key, index, discriminator (for TPH), and relationship:

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    modelBuilder
      .HasAnnotation("ProductVersion", "7.0.7")
      .HasAnnotation("Relational:MaxIdentifierLength", 128);

    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // → Entity configurations follow…
}
  • Annotations record EF version & server conventions
  • UseIdentityColumns: Enables SQL Server identity columns by default
  • modelBuilder.Entity(…): Repeated for each DomainClass

5. Entity Configurations (Highlights)

📋 Asset Entity

Property Type Notes
Id uniqueidentifier PK, generated on add
Category nvarchar(max) Required
Discriminator nvarchar(max) Stores derived type (TPH)
FieldOfficeId uniqueidentifier? FK → FieldOffice
ModelId int FK → AssetModel (Cascade delete)
OwnerId uniqueidentifier? FK → Employee
PurchaseDate datetimeoffset
Status nvarchar(max) Required
… …
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
    b.HasKey("Id");
    b.ToTable("Asset", "irby");
    b.HasIndex("FieldOfficeId");
    b.HasIndex("ModelId");
    b.HasIndex("OwnerId");
    b.HasDiscriminator<string>("Discriminator")
     .HasValue("Asset");
    b.UseTphMappingStrategy();
});

📋 Job Entity

Column CLR Type Nullable Description
JobId (PK) uniqueidentifier No Primary Key
JdeNumber nvarchar(450) Yes Unique Index
Name nvarchar(max) Yes Job Name
Status int No Job status code
ContractType nvarchar(max) Yes Type of contract
CustomerId uniqueidentifier? Yes FK (not enforced here)
FieldOfficeId uniqueidentifier? Yes FK → FieldOffice
GeoRegionCode nvarchar(max) Yes Geographic region short code
GeoRegionDescription nvarchar(max) Yes Full region description
JobType nvarchar(max) Yes e.g. “Construction”
ManagerId uniqueidentifier? Yes FK (Employee manager)
ProjectManagerId uniqueidentifier? Yes FK (Employee project manager)
RevenueDerivative nvarchar(max) Yes Algorithmic revenue categorizer
SuperintendentId uniqueidentifier? Yes FK (Employee superintendent)
WorkType nvarchar(max) Yes Nature of work
modelBuilder.Entity("IrbyImaging.DomainClasses.Job", b =>
{
    b.HasKey("JobId");
    b.HasIndex("FieldOfficeId");
    b.HasIndex("JdeNumber")
     .IsUnique()
     .HasFilter("[JdeNumber] IS NOT NULL");
    b.ToTable("Job", "irby");
});

📋 Employee Entity

  • PK: EmployeeId
  • Unique Index on JdeNumber
  • FKs: DepartmentId, JobId, RoleId
  • Fields: Name, Email, Status, ManagerId, etc.

See full code for dozens more DomainClasses (AssetHistory, AuditDetail, BillingInvoice, … up to TimeSheetEntry, Ticket, Update, Vehicle, and many ODS* read‑only views)._


6. Key Changes in Job Table

This migration primarily adds and updates the following columns on Job:

  • ContractType
  • CustomerId
  • GeoRegionCode & GeoRegionDescription
  • RevenueDerivative
  • (plus ensuring JdeNumber remains unique)

These augment the Job entity to support richer reporting and relational integrity with Customer and Employee (manager/project manager).


7. Relationships & Navigations

A selection of navigations configured:

Principal Entity Navigation Dependent Entity FK Property
AssetModel AssetsModelDetail AssetModelDetail AssetModelId
AssetModelDetail Make Manufacturer MakeId
FieldOffice Jobs Job FieldOfficeId
Job – FieldOffice FieldOfficeId
Job – Employee (Project…) ManagerId, …
Employee Assets Asset OwnerId
Employee TimeSheetEntries TimeSheetEntry EmployeeId
Ticket Updates Update TicketId

8. UML Class Diagram (Excerpt)

classDiagram
    class FieldOffice {
        +Guid Id
        +string Name
        -- Navigation --
        +Jobs[]
        +Assets[]
    }
    class Job {
        +Guid JobId
        +string JdeNumber
        +string Name
        +int Status
        +string ContractType
        +string GeoRegionCode
        +string GeoRegionDescription
        +string RevenueDerivative
    }
    FieldOffice "1" -- "0..*" Job : contains >
    class Employee {
        +Guid EmployeeId
        +string FirstName
        +string LastName
        +string Email
    }
    Job "1" -- "0..*" Employee : "Employees"

A full diagram would include 50+ entities—this is a focused excerpt.


9. Sample Usage & Commands

  1. Add Migration
    dotnet ef migrations add MoreUpdatesToJobTable2
    
  2. Update Database
    dotnet ef database update
    
  3. Inspect SQL
    dotnet ef migrations script 20240130142012_MoreUpdatesToJobTable2
    

When you run the update, EF Core reads this Designer snapshot and applies incremental SQL to align your irby schema.


🔚 Conclusion

This auto‑generated snapshot ensures your IrbyImaging domain remains in sync with your SQL Server schema. It meticulously describes every table, column, index, discriminator (for TPH inheritance), and relationship. The MoreUpdatesToJobTable2 migration enhances the Job table with richer metadata—paving the way for advanced reporting and stricter referential integrity.

Happy coding! 🚀