πŸ“ 20220613155005_NewColumnDocumentImageTable.Designer.cs Documentation


πŸš€ Table of Contents

  1. Overview & Purpose
  2. Migration Context
  3. Dependencies & Technologies
  4. Key Functional Areas
  5. Data Model Definitions
    5.1. Asset Hierarchy
    5.2. Document-Related Entities
    5.3. Other Core Entities
  6. Entity Relationships & Inheritance
  7. Spotlight: DocumentImage Entity Changes
  8. BuildTargetModel Method Walkthrough
  9. UML Class Diagram (Excerpt)
  10. How EF Core Uses This File
  11. Usage Examples
  12. Conclusion

1. Overview & Purpose

This auto-generated Designer file is part of the Entity Framework Core Migrations in the IrbyImaging.DbContext assembly. It captures the complete snapshot of the EF Core model after the migration named:

[Migration("20220613155005_NewColumnDocumentImageTable")]
public partial class NewColumnDocumentImageTable : Migration
{ 
    // ...
}

Purpose

  • Records table and column mappings.
  • Annotates primary/foreign keys, indexes, discriminator configurations for inheritance.
  • Ensures EF Core can compute diffs between model snapshots when adding/removing migrations.

2. Migration Context

🌟 Migration Name: 20220613155005_NewColumnDocumentImageTable
πŸ” What It Does:

  • Reflects new column(s) added to the DocumentImage table in the irby schema.
  • Updates the EF model snapshot to include these new properties so downstream migrations know the current state.

3. Dependencies & Technologies

Dependency Purpose
Microsoft.EntityFrameworkCore (v5.0.12) Core ORM framework
Microsoft.EntityFrameworkCore.Relational Relational database features (indexes, schema)
Microsoft.EntityFrameworkCore.SqlServer SQL Server provider
Microsoft.EntityFrameworkCore.Migrations Migrations API
IrbyImaging.DbContext assembly Contains the IrbyContext and domain classes

4. Key Functional Areas

  • Model Snapshot
    Defines how domain classes map to tables & columns.
  • Annotations & Conventions
    .HasAnnotation("ProductVersion", "5.0.12"), .HasAnnotation("SqlServer:ValueGenerationStrategy", IdentityColumn)
  • Entity Configurations
    Entities like Asset, DocumentImage, Employee, etc.
  • Inheritance Mapping
    Table-per-hierarchy via .HasDiscriminator() for Asset and its subclasses.

5. Data Model Definitions

5.1. Asset Hierarchy

Entity Table Discriminator
Asset (base) irby.Asset "Asset"
β”œβ”€ Computer irby.Asset "Computer"
β”œβ”€ DeskPhone irby.Asset "DeskPhone"
β”œβ”€ Dock irby.Asset "Dock"
β”œβ”€ MobileDevice irby.Asset "MobileDevice"
β”œβ”€ Monitor irby.Asset "Monitor"
β”œβ”€ NetworkEquipment irby.Asset "NetworkEquipment"
β”œβ”€ OfficePrinter irby.Asset "OfficePrinter"
β”œβ”€ Printer irby.Asset "Printer"
└─ SafetyEquipment irby.Asset "SafetyEquipment"
Entity Table Description
DocumentAttribute irby.DocumentAttribute Attributes (metadata) for docs
DocumentImage irby.DocumentImage Holds image contents & OCR results
DocumentType irby.DocumentType Type definitions
TempDocumentData irby.TempDocumentData Staging area for document data
IPMMigration irby.IPMMigration Legacy migration staging
IrbyForms irby.IrbyForms Special form images

5.3. Other Core Entities

  • AssetModel, AssetModelDetail, Manufacturer
  • Employee, Job, FieldOffice
  • GeneralLedger, GLTypeDetail, BillingInvoice
  • Ticket & Update (ticket history)
  • ODS_Employee_Staging, ODS_Jobs_Staging (ETL staging)
  • CovidTestData, RequestOption, Issue

6. Entity Relationships & Inheritance

  • Foreign Keys & Navigation

    • Asset β†’ AssetModel (ModelId)
    • Asset β†’ FieldOffice (FieldOfficeId)
    • Asset β†’ Employee (OwnerId)
    • Computer/SafetyEquipment β†’ OperatingSystem
    • Employee β†’ Job
    • FieldOffice β†’ Employee (Manager/ProjectManager/Superintendent)
    • Ticket β†’ Update
  • Inheritance (TPH)
    All subtypes of Asset share the irby.Asset table; distinguished by the Discriminator column.


7. Spotlight: DocumentImage Entity Changes

This migration’s focus is on DocumentImage.
Here’s a before/after comparison (conceptual):

Column Type Notes
DocumentImageId uniqueidentifier Primary key
FileName nvarchar(max)
ImageContents varbinary(max)
DocumentNotes nvarchar(max) New notes field
DocumentIndexes nvarchar(max) New indexing metadata (JSON?)
... ... Other existing columns

Why?

  • Capture free‑form notes for a document.
  • Store structured indexes/tags for search & categorization.

8. BuildTargetModel Method Walkthrough

[DbContext(typeof(IrbyContext))]
[Migration("20220613155005_NewColumnDocumentImageTable")]
partial class NewColumnDocumentImageTable : Migration
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        // 1️⃣ Global annotations
        modelBuilder
            .HasAnnotation("Relational:MaxIdentifierLength", 128)
            .HasAnnotation("ProductVersion", "5.0.12")
            .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

        // 2️⃣ Entity configuration for DocumentImage
        modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
        {
            b.Property<Guid>("DocumentImageId").HasColumnType("uniqueidentifier");
            b.Property<string>("FileName").HasColumnType("nvarchar(max)");
            b.Property<byte[]>("ImageContents").HasColumnType("varbinary(max)");
            b.Property<string>("DocumentNotes").HasColumnType("nvarchar(max)");       // πŸ†• new column
            b.Property<string>("DocumentIndexes").HasColumnType("nvarchar(max)");     // πŸ†• new column
            // ... other properties ...
            b.HasKey("DocumentImageId").HasName("PrimaryKey_DocumentImageId");
            b.ToTable("DocumentImage", "irby");
        });

        // 3️⃣ More entities...
    }
}

Highlights

  • Each modelBuilder.Entity(...) block maps a CLR type to a table.
  • .Property<>() defines column name, type, nullability.
  • .HasKey(), .HasIndex(), .HasOne()/WithMany() set up PKs, indexes, FKs.

9. UML Class Diagram (Excerpt)

@startuml
class DocumentImage {
  +Guid DocumentImageId
  +string FileName
  +byte[] ImageContents
  +string DocumentNotes
  +string DocumentIndexes
  +bool IsDeleted
  +DateTime DocumentUploadedDate
  ...
}
DocumentImage --> DocumentType
DocumentImage --> Employee : DocumentUploadedBy
@enduml

Export with PlantUML to visualize entity properties and relationships.


10. How EF Core Uses This File

  1. Scaffold: When you add a migration (dotnet ef migrations add ...), EF generates the .cs & .Designer.cs.
  2. Snapshot: The Designer file is the model snapshot – EF compares it to the live model to generate future diffs.
  3. Apply: On dotnet ef database update, EF ensures DB schema aligns with the latest migration scripts (not the Designer).

11. Usage Examples

Add a Migration

dotnet ef migrations add NewColumnDocumentImageTable \
  --project IrbyImaging.DbContext \
  --startup-project IrbyImaging.WebApi

Update Database

dotnet ef database update 20220613155005_NewColumnDocumentImageTable

Accessing the New Columns in Code

using var db = new IrbyContext();
var doc = await db.DocumentImages.FindAsync(someId);
doc.DocumentNotes = "Scanned on site by John Doe.";
doc.DocumentIndexes = "[\"invoice\",\"contract\"]";
await db.SaveChangesAsync();

12. Conclusion

This Designer snapshot is a vital piece of the EF Core Migrations machinery. It:

  • Guarantees consistency between your C# domain model and database schema.
  • Documents every entity, property, index, and relationship.
  • Ensures that the DocumentImage table now contains the newly introduced fields DocumentNotes and DocumentIndexes.

By understanding its structure, you can confidently extend your data model, add migrations, and maintain schema evolution in a controlled, repeatable manner. πŸŽ‰


Happy coding! πŸ› οΈ