📦 IrbyImaging.DbContext/Migrations/20240131195020_AddMoreColumnsToJobTable.Designer.cs


Auto‑Generated EF Core Migration Designer
This file is auto‑generated by Entity Framework Core to represent the target model after applying the 20240131195020_AddMoreColumnsToJobTable migration.
Do not edit this file manually; use the .cs migration file (without .Designer) to add or remove columns, relationships, etc.


📋 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Migration Class: AddMoreColumnsToJobTable
  4. Key Functional Areas
  5. Representative Entity Mappings
  6. UML Class Diagram (Mermaid)
  7. How to Use This Migration
  8. Conclusion

🔍 Overview & Purpose

This Designer file defines the complete EF Core model (all entities, properties, relationships, schemas) after the AddMoreColumnsToJobTable migration is applied. It does not contain the actual column‑addition code (that lives in the .cs file) but instead captures the “snapshot” of the model so EF can diff changes and generate future migrations.

  • Why it exists: EF Core uses this to know what the database should look like at this point in time.
  • When it runs:
    • During dotnet ef migrations add to compute diffs.
    • During dotnet ef database update to verify the model.

⚙️ Dependencies & Technologies

Technology Version
Microsoft.EntityFrameworkCore 7.0.7
Microsoft.EntityFrameworkCore.SqlServer 7.0.7
.NET SDK ≥ .NET 7
C# Language 11+

🗂 Migration Class: AddMoreColumnsToJobTable

[DbContext(typeof(IrbyContext))]
[Migration("20240131195020_AddMoreColumnsToJobTable")]
partial class AddMoreColumnsToJobTable
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        // … very long fluent‑API configuration …
    }
}

Migration Attributes

  • [DbContext(typeof(IrbyContext))]
    Binds this migration to the IrbyContext EF DbContext.
  • [Migration("20240131195020_AddMoreColumnsToJobTable")]
    Unique identifier (timestamp + name) for ordering.

BuildTargetModel Method

All entity types, table mappings, column definitions, keys, indexes, relationships, and discriminators are configured here via the Fluent API:

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

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
  • Annotations: EF Core version, SQL Server identifier length.
  • Extensions: UseIdentityColumns indicates the default PK generation strategy.

🔑 Key Functional Areas

1. Entity Configurations

  • Properties: .Property<T>("Name") + .HasColumnType(...), .IsRequired(), etc.
  • Keys: .HasKey("Id").
  • Indexes: .HasIndex("ForeignKeyId").
  • Schemas & Tables:
    b.ToTable("Job", "irby");
    
    Many tables live in irby schema.

2. Inheritance & Discriminators

  • TPH (Table‑Per‑Hierarchy) for assets:
    modelBuilder.Entity("IrbyImaging.DomainClasses.Asset")
        .HasDiscriminator<string>("Discriminator")
        .HasValue("Asset");
    
  • Derived Types:
    modelBuilder.Entity("IrbyImaging.DomainClasses.Computer")
        .HasBaseType("IrbyImaging.DomainClasses.Asset")
        .HasDiscriminator().HasValue("Computer");
    
    All asset sub‑classes share the Asset table with a Discriminator column.

3. Relationships & Navigation Properties

Relationship Config Example
One‑to‑Many Asset → AssetModel .HasOne("AssetModel").WithMany().HasForeignKey("ModelId")
One‑to‑Many Job → Employee .HasOne("Job").WithMany("Employees").HasForeignKey("JobId")
Many‑to‑One AssetHistory → Asset .HasOne("Asset").WithMany().HasForeignKey("AssetId")
Composite Entities (LinkUserRole, LinkRolePermission) .WithMany().HasForeignKey("RoleId","EmployeeId"/"PermissionId")

Each entity config ends with .Navigation("…") registrations for EF change‑tracking.


📝 Representative Entity Mappings

Below are selected examples illustrating the kind of configuration in this file.

Asset

Property Type Constraints
Id Guid PK, Identity
Category string Required
ModelId int FK → AssetModel.Id
PurchaseDate DateTimeOffset
Discriminator string TPH‑discriminator
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
    b.Property<Guid>("Id").ValueGeneratedOnAdd().HasColumnType("uniqueidentifier");
    b.Property<string>("Category").IsRequired().HasColumnType("nvarchar(max)");
    b.Property<int>("ModelId").HasColumnType("int");
    b.Property<DateTimeOffset>("PurchaseDate").HasColumnType("datetimeoffset");

    b.HasKey("Id");
    b.HasIndex("ModelId");
    b.ToTable("Asset", "irby");
    b.HasDiscriminator<string>("Discriminator").HasValue("Asset");
});

Job

🆕 New Columns Added in this migration likely include extra dates or owner fields on Job.
(The .Designer.cs does not explicitly highlight them — they are part of the snapshot.)

modelBuilder.Entity("IrbyImaging.DomainClasses.Job", b =>
{
    b.Property<Guid>("JobId")
        .ValueGeneratedOnAdd()
        .HasColumnType("uniqueidentifier");

    b.Property<string>("JdeNumber")
        .HasColumnType("nvarchar(450)")
        .IsRequired(false);

    b.Property<DateTime?>("DatePlannedStart").HasColumnType("datetime2");
    b.Property<DateTime?>("DateActualStart").HasColumnType("datetime2");
    b.Property<DateTime?>("DatePlannedComplete").HasColumnType("datetime2");
    b.Property<DateTime?>("DateActualComplete").HasColumnType("datetime2");

    b.HasKey("JobId");
    b.HasIndex("JdeNumber").IsUnique().HasFilter("[JdeNumber] IS NOT NULL");
    b.ToTable("Job", "irby");
});

Computer (TPH Example)

modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b =>
{
    b.HasBaseType("IrbyImaging.DomainClasses.Asset");

    b.Property<string>("AssetNumber")
     .ValueGeneratedOnUpdateSometimes()
     .HasColumnName("AssetNumber");

    b.Property<int>("OperatingSystemId")
     .ValueGeneratedOnUpdateSometimes()
     .HasColumnName("OperatingSystemId");

    b.HasIndex("OperatingSystemId");
    b.ToTable("Asset", "irby");
    b.HasDiscriminator().HasValue("Computer");
});
  • BaseType: Asset
  • Discriminator Value: “Computer”
  • Extra Props: AssetNumber, OperatingSystemId → FK to OperatingSystem table.

📐 UML Class Diagram (Mermaid)

classDiagram
  %% Core domain classes
  Asset <|-- Computer
  Asset <|-- DeskPhone
  Asset <|-- MobileDevice
  Asset <|-- Monitor
  Asset <|-- NetworkEquipment
  Asset <|-- OfficePrinter
  Asset <|-- Printer
  Asset <|-- SafetyEquipment
  
  Computer --> OperatingSystem
  Asset --> AssetModel
  AssetModel --> Manufacturer
  Asset <-- AssetHistory
  Employee --> Role
  Employee --> Department
  Job --> FieldOffice
  Job --> Employee : Employees
  FieldOffice --> Employee : AsstProjectManager / Manager / …
  LinkUserRole --> Employee
  LinkUserRole --> Role
  LinkRolePermission --> Role
  LinkRolePermission --> Permissions

🔄 How to Use This Migration

Apply Migration

# Ensure the connection string is configured in IrbyContext
dotnet ef database update 20240131195020_AddMoreColumnsToJobTable

Revert Migration

# Roll back one step (undo the last migration)
dotnet ef database update <PreviousMigrationName>

✅ Conclusion

  • What it is: An EF Core‑generated model snapshot for the AddMoreColumnsToJobTable migration.
  • Purpose: EF Core uses it internally to track the state of your DbContext’s model.
  • Key Takeaways:
    • Fluent API defines table/column details, keys, indexes, relationships.
    • TPH inheritance centralizes asset sub‑types.
    • Discriminators and Schemas organize multi‑tenant or multi‑module systems.

🎉 You’re now equipped to understand how EF Core translates your C# domain classes into a concrete database schema snapshot! 🚀