🔧 IrbyImaging.DbContext Migrations Designer Documentation (2022‑02‑07)


🗂️ Table of Contents

  1. Overview & Purpose
  2. Migration Class & Attributes
  3. BuildTargetModel Method
  4. Entity Configurations
    4.1. Core Entities
    4.2. Inheritance & Discriminator Setup
    4.3. Relationships & Navigation Properties
  5. Dependencies & Technologies
  6. How to Use Migrations
  7. UML Entity Diagram
  8. Conclusion

1. Overview & Purpose

This file, 20220207182630_Migrations.Designer.cs, is auto‑generated by Entity Framework Core (EF Core) as part of the migration snapshot for the IrbyContext. It captures the shape of your database schema—entities, properties, relationships, table mappings, indexes, and inheritance hierarchies—at the time you ran:

dotnet ef migrations add Migrations --context IrbyContext

Key Objectives

  • 🎯 Preserve a “snapshot” of the EF Core model
  • 📦 Drive incremental changes to the database schema
  • 🛠️ Provide metadata for dotnet ef database update

Note: Do not manually edit this file. Changes should be applied by updating domain classes or creating new migrations.


2. Migration Class & Attributes

namespace IrbyImaging.DbContext.Migrations
{
    [DbContext(typeof(IrbyContext))]
    [Migration("20220207182630_Migrations")]
    partial class Migrations : Migration
    {
        // ...
    }
}
Attribute Purpose
[DbContext(typeof(...))] Links this migration to the IrbyContext
[Migration("yyyyMMddHHmmss_Name")] Unique timestamp + name identifier for ordering and scaffold commands

3. BuildTargetModel Method

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    #pragma warning disable 612, 618
    modelBuilder
        .HasAnnotation("Relational:MaxIdentifierLength", 128)
        .HasAnnotation("ProductVersion", "5.0.12")
        .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
    // Entity configurations follow...
    #pragma warning restore 612, 618
}
  • ModelBuilder Annotations

    • Relational:MaxIdentifierLength ⇒ 128 characters
    • ProductVersion ⇒ EF Core v5.0.12
    • SqlServer:ValueGenerationStrategy ⇒ IDENTITY columns by default
  • #pragma warning disable
    Temporarily silences obsolete‐API warnings generated by scaffolded code.


4. Entity Configurations

EF Core uses fluent API calls inside BuildTargetModel to map your C# classes to tables, columns, keys, indexes, relationships, and inheritance. Below is a condensed overview.

4.1. Core Entities

Entity Schema.Table PK Special Notes
Asset irby.Asset Id : Guid Base of all asset types; discriminator
AssetHistory irby.AssetHistory Id : Guid Audit trail of asset changes
AssetModel irby.AssetModel Id : int FK → Manufacturer
AssetModelDetail AssetModelDetail Id : int Additional model attributes
CovidTestData irby.CovidTestData CovidTestDataId : Guid Test results / images
DocumentImage irby.DocumentImage DocumentImageId : Guid OCR, metadata
Employee irby.Employee Id : Guid Unique JDE; FK → Job
FieldOffice irby.FieldOffice Id : Guid Unique JDE; FK → Manager(Employee)
IPMMigration irby.IPMMigration IPMMigrationId : Guid Bulk document migration metadata
Job irby.Job Id : Guid Unique JDE
Manufacturer irby.AssetManufacturer Id : int Asset makes
ODSEmployee irby.ODS_Employee_Staging EMPLOYEE_NUMBER : string Staging table from ODS
ODSJob irby.ODS_Jobs_Staging ORG_BU : string Staging table from ODS
OperatingSystem irby.OperatingSystem Id : int OS lookup
TempDocumentData irby.TempDocumentData TempDocumentDataId : Guid Temporary document store

4.2. Inheritance & Discriminator Setup

The Asset entity uses Table‐Per‐Hierarchy (TPH) to store multiple C# subclasses in one table (irby.Asset). A special column Discriminator identifies the subtype.

CLR Type Discriminator Value
Asset "Asset"
Computer "Computer"
DeskPhone "DeskPhone"
Dock "Dock"
MobileDevice "MobileDevice"
Monitor "Monitor"
NetworkEquipment "NetworkEquipment"
OfficePrinter "OfficePrinter"
Printer "Printer"
SafetyEquipment "SafetyEquipment"

4.3. Relationships & Navigation Properties

Principal Entity Dependent Entity(s) FK Property Delete Behavior
AssetModel AssetModelDetail AssetModelId Cascade on Make
Manufacturer AssetModel MakeId Cascade
Employee (Job) Employee CurrentJobId Cascade
Employee (assets) Asset OwnerId ClientSetNull
FieldOffice Asset FieldOfficeId ClientSetNull
FieldOffice (manager) FieldOffice ManagerId Cascade
ODSEmployee (job) ODSEmployee ORG_BU Cascade
Computer / SafetyEquipment OperatingSystem OperatingSystemId Cascade

🔗 Navigation properties are enabled via b.Navigation("PropertyName") calls at the end of each entity block.


5. Dependencies & Technologies 📦

  • .NET 5.0 and C# 9
  • Entity Framework Core 5.0.12
  • SQL Server provider (Microsoft.EntityFrameworkCore.SqlServer)
  • Fluent API for model configuration
  • Value converters (e.g., DateTimeOffset)

6. How to Use Migrations 🛠️

  1. Scaffold a New Migration
    dotnet ef migrations add <MigrationName> --context IrbyContext
    
  2. Apply to Database
    dotnet ef database update --context IrbyContext
    
  3. Rollback / Revert
    dotnet ef database update <PreviousMigration> --context IrbyContext
    

Tip: Inspect this designer file to verify how EF Core interprets your domain classes.


7. UML Entity Diagram 📈

erDiagram
    Asset ||--o{ AssetHistory : logs
    Asset ||--|{ AssetModelDetail : has
    AssetModel ||--o{ AssetModelDetail : defines
    Manufacturer ||--o{ AssetModel : makes
    Job ||--o{ Employee : employs
    Employee ||--o{ Asset : owns
    FieldOffice ||--o{ Asset : houses
    ODSEmployee ||--|| ODSJob : works_in
    OperatingSystem ||--o{ Computer : runs
    OperatingSystem ||--o{ SafetyEquipment : runs

8. Conclusion ✅

This Designer snapshot is the cornerstone for EF Core’s migration engine. It guarantees that your C# classes and relational database stay in sync over time. Always:

  • Keep domain classes authoritative
  • Generate migrations via CLI
  • Review—never manually edit—the designer code

Happy migrating! 🚀