📚 Migration Documentation

File: IrbyImaging.DbContext/Migrations/20250115200800_RemoveCityAndAddColumnsToCounty.Designer.cs
Migration: RemoveCityAndAddColumnsToCounty
DbContext: IrbyContext


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. BuildTargetModel Method Explained
  5. Data Models (Entities)
  6. Relationships & Mappings
  7. Schema & Table Configuration
  8. Inheritance & TPH (Table‑Per‑Hierarchy)
  9. SQL‑Server Identity Configuration
  10. Sample Code Blocks & Usage Examples
  11. UML Diagram (Mermaid)
  12. Conclusion

1. Overview & Purpose

This auto-generated designer file is part of Entity Framework Core Migrations. It represents the snapshot of your model after applying the RemoveCityAndAddColumnsToCounty migration.
It is used by EF Core to:

  • Compute differences between your model and the database.
  • Generate SQL for Up / Down migrations.
  • Support the EF CLI and Visual Studio tooling.

⚠️ Note: Do not manually edit designer files. They will be overwritten by EF Core.


2. Dependencies & Technologies

Technology Version Purpose
Microsoft.EntityFrameworkCore 9.0.0 ORM mapping
Microsoft.EntityFrameworkCore.SqlServer 9.0.0 SQL Server provider
.NET / C# .NET 8 / C# 12 Application platform
SQL Server 2019+ Relational database

Third‑party NuGet packages are limited to EF Core core and SQL Server provider.


3. Key Functional Areas

  1. Model Snapshot
    Captures every entity, property, key, index, relationship, discriminator, schema, and annotation.

  2. Database Schema Management
    Enables EF Core to compare the current model against the last migration and produce DDL scripts.

  3. Change Tracking
    Represents changes in tables (e.g., Remove City, Add Columns to County) that this migration applies.


4. BuildTargetModel Method Explained

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

    // Use SQL‑Server IDENTITY style
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // Then, configure each entity…
    modelBuilder.Entity("IrbyImaging.DomainClasses.County", b => {
        b.Property<Guid>("CountyId")
            .ValueGeneratedOnAdd()
            .HasColumnType("uniqueidentifier");
        // … other column configurations …
        b.ToTable("County", "irby");
    });

    // Many more entity configurations follow…
}
  • Annotations

    • "ProductVersion": "9.0.0" – EF Core version.
    • "Relational:MaxIdentifierLength": 128 – Max DB identifier length.
  • UseIdentityColumns
    Configures integer primary keys with IDENTITY(1,1) by default on SQL Server.

  • Entity Configuration
    For each CLR type (by full name), EF Core:

    • Declares properties and their database types.
    • Defines primary keys (HasKey).
    • Sets up indexes (HasIndex).
    • Maps to tables and schemas (ToTable("...", "irby")).
    • Defines relationships (HasOne, WithMany, OnDelete).

5. Data Models (Entities)

The migration snapshot contains 100+ entities. Below is a top‑level summary by domain:

5.1 Financial Entities

Entity Table (Schema) Key Main Columns
AccountBalances AccountBalances (irby) AccountBalanceId Cost, Revenue, ManHours, Month/Year
AccountLedger AccountLedger (irby) AccountLedgerId Amount, GLDate, DocumentType
GeneralLedger GeneralLedger (irby) Id Code, Description
GLTypeDetail GLTypeDetail Id Code, Description, GeneralLedgerId
WIP WIP (irby) WIPId Cost, Revenue, Margin, ReportMonth

5.2 Asset Management Entities

Entity Table (Schema) Key Main Columns
Asset (base class) Asset (irby) Id Category, ModelId, Status
AssetHistory AssetHistory (irby) Id Action, Timestamp, OwnerId
AssetModel AssetModel (irby) Id Name, Category, MakeId
AssetModelDetail AssetModelDetail Id Name, Category, MakeId
Sub‑types (TPH) Asset (irby) (discriminator) Computer, MobileDevice, Printer…

5.3 Auditing Entities

Entity Table (Schema) Key Main Columns
AuditDetail AuditDetail (irby) AuditDetailId ActionName, UserId, RoleId
AuditReport AuditReport No PK Flattened report view

5.4 Document Management Entities

Entity Table (Schema) Key Main Columns
DocumentImage DocumentImage (irby) DocumentImageId BlobName, ContentType, OCR, Indexes
TempDocumentData TempDocumentData (irby) TempDocumentDataId ImageContents, ReferenceId
BlobData BlobData (irby) BlobDataId ImageContents
DocumentCategory DocumentCategory (irby) Id Name, IsLegalDocument
DocumentType DocumentType (irby) Id Type, ImagingType, IsAccounting
DocumentAttribute DocumentAttribute (irby) Id AttributeName, Values, Link flags

5.5 HR & Employee Entities

Entity Table (Schema) Key Main Columns
Employee Employee (irby) EmployeeId DisplayName, JdeNumber, Status, DepartmentId
Department Department (irby) DepartmentId Name, IsDeleted
LinkUserRole LinkUserRole (irby) Id EmployeeId, RoleId
Role Role (irby) RoleId Name, Description
Permissions Permissions (irby) PermissionId PermissionName
LinkRolePermission LinkRolePermission (irby) Id RoleId, PermissionId
TimeSheetEntry TimeSheetEntry (irby) TimeSheetEntryId EmployeeId, HoursWorked, DateWorked
TimeEntryType TimeEntryType (irby) TimeEntryTypeId Name

5.6 Job & Work Order Entities

Entity Table (Schema) Key Main Columns
Job Job (irby) JobId Name, JdeNumber, FieldOfficeId, Status
CostCode CostCode (irby) CostCodeId JobId, CostCodeNumber, Name
PurchaseOrder PurchaseOrder (irby) PurchaseOrderId JobId, OrderNumber, VendorName
WorkOrder WorkOrder (irby) WorkOrderId JobId, Status, EstimatedHours

5.7 Geography & Location Entities

Entity Table (Schema) Key Main Columns
County County (irby) CountyId CountyName, StateCode, TimeZone
State State (irby) Id Name, Abbreviation, Code
GeoLocation GeoLocations No PK DocumentImageId, Latitude, Longitude
JobAndFieldOfficeMapping JobAndFieldOfficeMapping No PK FieldOfficeId, JobNumber, Latitude

5.8 Support & Lookup Entities

Entity Table (Schema) Key Main Columns
CarrierType CarrierType (irby) Id Carrier
CarrierTypeDetail CarrierTypeDetail Id CarrierTypeId, IsInactive
ContractTypeDetails ContractTypeDetails (irby) Id TypeOfWork, NumberOfContracts
ContractTypeNumber ContractTypeNumber (irby) Id DocumentType, TypeCount
ContractsByLead ContractsByLead (irby) Id Director, NumberOfContracts
RequestOption RequestOption (irby) Id Item, ApprovalRequired
FieldOffice FieldOffice (irby) Id Name, JdeNumber
EquipmentClass EquipmentClass EquipmentClassId ClassId, Name
EquipmentType EquipmentType EquipmentTypeId TypeId, EquipmentClassId
OperatingSystem OperatingSystem (irby) Id Name, IsAvailableOption

6. Relationships & Mappings

  • One-to-Many:

    • FieldOffice → Assets, Jobs.
    • Job → CostCodes, Employees, PurchaseOrders, WorkOrders.
  • Many-to-One:

    • Employee → Department, Job, Role.
    • Asset → AssetModel, FieldOffice, Owner (Employee).
  • Link / Join Tables

    • LinkUserRole connects Employee ↔︎ Role.
    • LinkRolePermission connects Role ↔︎ Permissions.
  • Cascade Delete
    Many relationships use OnDelete(DeleteBehavior.Cascade), ensuring DB consistency.


7. Schema & Table Configuration

  • Default schema for most tables: irby.
  • Some “view‑type” or reporting tables omit schema or use default.
  • Table names match CLR entity names by convention, except lower‑level underscores or plurals.

8. Inheritance & TPH (Table‑Per‑Hierarchy)

Entity: Asset
Strategy: Single table “Asset” with Discriminator column:

  • Base: Asset
  • Subtypes:
    • Computer
    • DeskPhone
    • Dock
    • MobileDevice
    • Monitor
    • NetworkEquipment
    • OfficePrinter
    • Printer
    • SafetyEquipment

Discriminator column and per‑type columns allow storing all asset sub‑classes in one table.


9. SQL‑Server Identity Configuration

All integer PKs and identity-like columns call:

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));

ensuring:

  • IDENTITY(1,1) on auto‑increment columns.
  • Compatibility with SQL Server’s identity generation.

10. Sample Code Blocks & Usage Examples

Adding & Applying Migration

# Dotnet-CLI
dotnet ef migrations add RemoveCityAndAddColumnsToCounty
dotnet ef database update

# Package Manager Console
Add-Migration RemoveCityAndAddColumnsToCounty
Update-Database

Inspecting Generated SQL

dotnet ef migrations script --output RemoveCityAndAddColumnsToCounty.sql

11. UML Diagram (Mermaid)

Below is a simplified Entity‑Relationship snippet focusing on County and related Job:

erDiagram
    COUNTY {
        GUID CountyId PK
        string CountyName
        string StateCode
        string TimeZone
        string AreaCode
        string ZipCode
    }
    JOB {
        GUID JobId PK
        string Name
        string JdeNumber
        GUID? FieldOfficeId FK
    }
    FIELD_OFFICE {
        GUID Id PK
        string Name
        string JdeNumber
    }
    COUNTY ||--o{ JOB : "serves region"
    FIELD_OFFICE ||--o{ JOB : "manages jobs"

🌐 You can extend the diagram by adding other entities (e.g., Employee, Asset, DocumentImage) similarly.


12. Conclusion

This designer file is a comprehensive snapshot of your EF Core model after the RemoveCityAndAddColumnsToCounty migration. It ensures that EF Core can:

  • Compare and migrate the database schema reliably.
  • Maintain a single source of truth for entity mappings.
  • Support incremental schema evolution.

By understanding its structure, you’ll be better equipped to:

  • Diagnose migration issues.
  • Extend your model safely.
  • Leverage advanced EF Core features (inheritance, composite keys, TPH).

✨ Happy coding!