πŸ“¦ IrbyImaging.DbContext/Migrations/20220809153958_UpdateDocImageTable.Designer.cs Documentation


File Path
IrbyImaging.DbContext/Migrations/20220809153958_UpdateDocImageTable.Designer.cs

Generated by
Entity Framework Core (5.0.12)
Purpose
Captures the target model snapshot for the UpdateDocImageTable migration, used by EF Core to build and compare the database schema.


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. BuildTargetModel Method
  4. Entity Models & Data Schema
  5. Key Functional Areas
  6. Entity Configuration Examples
  7. Relationships & Associations
  8. Inheritance & Discriminator Mapping
  9. Usage & Execution
  10. UML Diagram (Mermaid)
  11. Additional Sections
  12. Conclusion

1. Overview & Purpose πŸ“–

This Designer file is an auto-generated snapshot of your EF Core model at the point in time of the migration named 20220809153958_UpdateDocImageTable. It contains:

  • The BuildTargetModel(ModelBuilder modelBuilder) method
  • Entity definitions (tables, columns, PKs, FKs, indexes)
  • Inheritance (TPH via discriminators)

❗ Note:

You should not manually edit this file.
EF Core will overwrite it when you add or remove migrations.


2. Dependencies & Technologies πŸ”—

Component Version / Type
.NET 5.0
C# 9.0
Entity Framework Core 5.0.12
Database Provider Microsoft.EntityFrameworkCore.SqlServer
EF Core Tools dotnet ef CLI

Key Namespaces:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

3. BuildTargetModel Method 🚧

At the heart of this file lies:

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);

    // ... hundreds of .Entity(...) calls for each domain class
    #pragma warning restore 612, 618
}
  • Purpose: Defines how each CLR class maps to a database table.
  • Annotations:
    • MaxIdentifierLength sets max length of SQL identifiers.
    • ProductVersion records EF Core version.
    • ValueGenerationStrategy configures identity columns.

4. Entity Models & Data Schema πŸ“Š

This migration snapshot covers 40+ entities. They can be grouped by business area:

Domain Area Entities
Asset Management Asset, AssetHistory, AssetModel, AssetModelDetail, Manufacturer, OperatingSystem, Computer, DeskPhone, Dock, MobileDevice, Monitor, NetworkEquipment, OfficePrinter, Printer, SafetyEquipment
Document Handling DocumentImage, DocumentType, DocumentCategory, DocumentAttribute, TempDocumentData, IPMMigration, IrbyForms
Human Resources Employee, ODS_Employee_Staging, ODS_Jobs_Staging, FieldOffice, Job
Billing & GL BillingInvoice, CarrierType, CarrierTypeDetail, GeneralLedger, GLTypeDetail
Ticketing System Ticket, Update
Compliance & Other CovidTestData, Issue, RequestOption, State

5. Key Functional Areas πŸ”‘

  1. Schema Definition

    • Tables, columns, data types
    • Primary keys & foreign keys
    • Indexes & unique constraints
  2. Inheritance & TPH Discriminators

    • Asset hierarchy (Computer, MobileDevice, etc.)
    • Uses Discriminator column on table "Asset","irby"
  3. Navigation Properties

    • One-to-many, many-to-one relationships
    • Cascade delete behaviors
  4. Migrations Support

    • Snapshot used to generate Up() / Down() SQL
    • EF Core CLI orchestration

6. Entity Configuration Examples πŸ”

6.1 DocumentImage

modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
    b.ToTable("DocumentImage","irby");
    b.HasKey("DocumentImageId").HasName("PrimaryKey_DocumentImageId");

    b.Property<Guid>("DocumentImageId").HasColumnType("uniqueidentifier");
    b.Property<byte[]>("ImageContents").HasColumnType("varbinary(max)");
    b.Property<string>("DocumentType").HasColumnType("nvarchar(max)");
    b.Property<bool>("IsLegalDocument").HasColumnType("bit");
    // … other properties …

    // No direct FKs; reference via DocumentType or Category name fields
});

6.2 Asset (TPH + Discriminator)

modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
    b.ToTable("Asset", "irby");
    b.HasKey("Id");
    b.Property<Guid>("Id").ValueGeneratedOnAdd();

    b.Property<string>("Discriminator")
     .IsRequired()
     .HasColumnType("nvarchar(max)");

    // Base properties
    b.Property<string>("SerialNumber").HasColumnType("nvarchar(max)");
    // …

    // TPH Inheritance
    b.HasDiscriminator<string>("Discriminator")
     .HasValue("Asset");
});

6.3 Asset β†’ Computer Subclass

modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b =>
{
    b.HasBaseType("IrbyImaging.DomainClasses.Asset");
    b.Property<int>("OperatingSystemId")
     .HasColumnType("int");
    b.HasIndex("OperatingSystemId");

    b.ToTable("Asset","irby");
    b.HasDiscriminator().HasValue("Computer");

    // Relationship
    b.HasOne("IrbyImaging.DomainClasses.OperatingSystem", "OperatingSystem")
     .WithMany()
     .HasForeignKey("OperatingSystemId")
     .OnDelete(DeleteBehavior.Cascade);
});

7. Relationships & Associations πŸ”—

  • One-to‐Many

    • AssetModel β†’ AssetModelDetail
    • FieldOffice β†’ Asset
    • Ticket β†’ Update
    • Job β†’ Employee
  • Many-to‐One

    • Asset β†’ AssetModel
    • Asset β†’ Employee (Owner)
  • Cascade Deletes

    • Removing a Job will remove its Employees.
    • Deleting an OperatingSystem cascade‐deletes its Computer assets.

8. Inheritance & Discriminator Mapping 🏷️

All device‐type classes inherit from the Asset base:

classDiagram
    class Asset {
      +Guid Id
      +string Discriminator
      +string SerialNumber
      +...
    }
    class Computer
    class MobileDevice
    class DeskPhone
    class Monitor
    Asset <|-- Computer
    Asset <|-- MobileDevice
    Asset <|-- DeskPhone
    Asset <|-- Monitor
  • Single Table Inheritance (TPH)
  • Discriminator Column: "Discriminator"
  • Values: "Computer", "MobileDevice", "DeskPhone", etc.

9. Usage & Execution πŸš€

Generating a Migration

dotnet ef migrations add UpdateDocImageTable
  • Creates two files:
    • 20220809153958_UpdateDocImageTable.cs
    • 20220809153958_UpdateDocImageTable.Designer.cs (this file)

Applying to Database

using (var context = new IrbyContext())
{
    context.Database.Migrate();
}
  • EF Core uses the Designer snapshot to decide what SQL to run.

10. UML Diagram (Mermaid) πŸ“ˆ

Below is a simplified class diagram for the Document domain:

classDiagram
    class DocumentImage {
      +Guid DocumentImageId
      +byte[] ImageContents
      +string DocumentType
      +bool IsLegalDocument
      +int Page
      +int TotalPages
    }
    class DocumentType {
      +Guid Id
      +string Type
      +string DocumentCategory
    }
    class DocumentCategory {
      +Guid Id
      +string Name
      +string Description
    }

    DocumentImage --> DocumentType : uses
    DocumentType --> DocumentCategory : categorizes

11. Additional Sections πŸ“‹

View Models & Data Models

  • Data Models: All EF Core entity classes in the modelBuilder.Entity(...) calls.
  • View Models: N/A (not part of migration snapshot).

Helper Methods / Utilities

  • BuildTargetModel: Central method; no additional helpers.

Error Handling and Return Types

  • Not applicable; this file simply describes the schema.

API Endpoints Overview

  • Not applicable; data access layer only.

Third-party Integrations

  • Only EF Core and SQL Server provider.

12. Conclusion βœ…

This Designer migration file is your schema snapshot for EF Core. It ensures consistency between your domain classes and the database.

  • Do not edit it manually.
  • When you add, remove, or rename entities/properties, always generate a new migration.
  • Use dotnet ef commands or context.Database.Migrate() to keep your database in sync.

Happy coding! πŸŽ‰