📚 Documentation: 20221102194233_AddNewColumnDocumentImageTable.Designer.cs

Auto-generated EF Core migration designer
This file is part of the Entity Framework Core Migrations infrastructure. It represents the model snapshot after applying the AddNewColumnDocumentImageTable migration on the IrbyContext.
Do not edit this file manually—changes will be overwritten by EF Core.


🗂️ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
    • Migration Class Definition
    • BuildTargetModel Method
  4. Data Models & Mappings
    • Domain Areas & Entities
    • DocumentImage Entity (focus of this migration)
  5. Relationships & Navigations
  6. Helper Methods / Utilities
  7. Usage & Examples
    • Applying the Migration
    • Command-Line Snippets
  8. UML Diagram (Mermaid)
  9. Conclusion

🔍 Overview & Purpose

This Designer file is part of the EF Core Migration named 20221102194233_AddNewColumnDocumentImageTable. It does not contain the Up()/Down() logic (that’s in the .cs file), but it carries the model snapshot for all entities in the IrbyContext as of this migration.

  • Why? EF Core keeps a snapshot of your model so it can compute future migrations correctly.
  • What’s inside? A single method, BuildTargetModel(ModelBuilder modelBuilder), which:
    • Defines all entity types
    • Maps CLR classes to tables and columns
    • Configures keys, indexes, relationships, schemas, and value generation
    • Sets up TPH (Table‑Per‑Hierarchy) for inherited types (e.g., Asset → Computer, MobileDevice, etc.)

🔧 Dependencies & Technologies

Technology Version Purpose
.NET 5.0 5.0.12 Target framework
Microsoft.EntityFrameworkCore 5.0.12 Core ORM
Microsoft.EntityFrameworkCore.SqlServer 5.0.12 SQL Server provider
Microsoft.EntityFrameworkCore.Design 5.0.12 Migrations / tooling

🚀 Key Functional Areas

1. Migration Class Definition

namespace IrbyImaging.DbContext.Migrations
{
    [DbContext(typeof(IrbyContext))]
    [Migration("20221102194233_AddNewColumnDocumentImageTable")]
    partial class AddNewColumnDocumentImageTable
    {
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            // ... entity mappings ...
        }
    }
}
  • Attributes
    • [DbContext(typeof(IrbyContext))] associates this migration with IrbyContext.
    • [Migration("20221102194233_AddNewColumnDocumentImageTable")] assigns a timestamped identifier.

2. BuildTargetModel Method

  • Purpose: Reconstructs the EF Core model as it should be after applying this migration.
  • Actions:
    • modelBuilder.HasAnnotation(...) sets global model annotations (e.g., SQL Server conventions).
    • Defines each entity with:
      • Property<...>("Name") to map CLR property to column
      • .HasColumnType("...") for SQL type
      • .IsRequired(), .ValueGeneratedOnAdd(), etc.
      • HasKey(), HasIndex(), ToTable("...", "schema")
      • TPH configuration via .HasDiscriminator()
      • Relationship mapping (HasOne(...) / .WithMany(...) / .HasForeignKey(...))
    • Finally, disables some warnings around obsolete APIs (#pragma warning disable 612, 618).

🗄️ Data Models & Mappings

Domain Areas & Entities

Below is a summary of the principal domain entities, their corresponding tables, schemas, and primary keys.

Domain Area Entity Table (Schema) Primary Key
Assets Asset Asset (irby) Id (GUID)
AssetHistory AssetHistory (irby) Id (GUID)
AssetModel AssetModel (irby) Id (int)
AssetModelDetail AssetModelDetail Id (int)
Manufacturer AssetManufacturer (irby) Id (int)
OperatingSystem OperatingSystem (irby) Id (int)
Documents DocumentImage DocumentImage (irby) DocumentImageId (GUID)
DocumentCategory DocumentCategory (irby) Id (GUID)
DocumentType DocumentType (irby) Id (GUID)
DocumentAttribute DocumentAttribute (irby) Id (GUID)
Billing BillingInvoice BillingInvoice (irby) Id (GUID)
CarrierType CarrierType (irby) Id (GUID)
CarrierTypeDetail CarrierTypeDetail (irby) Id (GUID)
GeneralLedger GeneralLedger (irby) Id (GUID)
GLTypeDetail GLTypeDetail Id (GUID)
COVID CovidTestData CovidTestData (irby) CovidTestDataId (GUID)
Customers Customer Customer (irby) Id (GUID)
Tracking IrbyForms IrbyForms (irby) FormId (GUID)
IPMMigration IPMMigration (irby) IPMMigrationId (GUID)
TempDocumentData TempDocumentData (irby) TempDocumentDataId (GUID)
Help Desk Ticket Ticket (irby) Id (GUID)
Update Update (irby) Id (GUID)
Issue Issue (irby) Id (GUID)
HR / Ops Employee Employee (irby) Id (GUID)
FieldOffice FieldOffice (irby) Id (GUID)
Job Job (irby) Id (GUID)
ODSEmployee ODS_Employee_Staging (irby) EMPLOYEE_NUMBER (str)
ODSJob ODS_Jobs_Staging (irby) ORG_BU (str)
Options & States RequestOption RequestOption (irby) Id (GUID)
State State (irby) Id (GUID)

🔦 DocumentImage Entity

This migration specifically deals with adding columns to the DocumentImage table. The snapshot shows the complete mapping:

Column Name CLR Type SQL Type Notes
DocumentImageId Guid uniqueidentifier Primary Key
AssignedToEmployeeId string nvarchar(max)
AssignedToEmployeeName string nvarchar(max)
CompanyId string nvarchar(max)
ContentType string nvarchar(max) MIME type
CustomerName string nvarchar(max)
CustomerNumber string nvarchar(max)
DocumentCategory string nvarchar(max) FK to DocumentCategory via name
DocumentIndexes string nvarchar(max) Serialized index values
DocumentNotes string nvarchar(max)
DocumentType string nvarchar(max) FK to DocumentType via type name
DocumentUploadedBy string nvarchar(max)
DocumentUploadedDate DateTime datetime2
FileName string nvarchar(max)
FiledDate string nvarchar(max) Archived date string
ImageContents byte[] varbinary(max) Binary PDF / Image
ImageOCRContents byte[] varbinary(max) Binary OCR data (new column!)
ImageOCRText string nvarchar(max) Extracted text (new column!)
IsDeleted bool bit Soft-delete flag
IsLegalDocument bool bit Indicates legal doc (new column!)
JobAddress string nvarchar(max)
JobDate string nvarchar(max)
JobKeyword string nvarchar(max)
JobName string nvarchar(max)
JobNumber string nvarchar(max)
JobOwner string nvarchar(max)
LegalDocumentType Guid uniqueidentifier FK to some legal doc type table?
OriginalReferenceId Guid uniqueidentifier Stores original batch reference
Page int int Page number
ReferenceId Guid uniqueidentifier Current batch reference
TotalPages int int Total pages
UnitNumber string nvarchar(max) Job unit / location

New Columns (added by this migration):

  • 🆕 ImageOCRContents
  • 🆕 ImageOCRText
  • 🆕 IsLegalDocument

🔗 Relationships & Navigations

This designer file also wires up foreign keys and navigations for related entities. A few highlights:

  • Asset → FieldOffice, Asset → Owner (Employee), Asset → AssetModel
  • AssetModel → Manufacturer
  • Employee → CurrentJob (Job)
  • FieldOffice → Manager, ProjectManager, Superintendent (all Employee)
  • Update → Ticket
  • Computer / SafetyEquipment → OperatingSystem
  • ODSEmployee → ODSJob

Note: DocumentImage stands alone (no FK mappings in this snapshot).


🛠️ Helper Methods / Utilities

  • Value Generation

    • .ValueGeneratedOnAdd(): for auto‑GUID and identities
    • .HasAnnotation("SqlServer:ValueGenerationStrategy", IdentityColumn)
  • Discriminator (TPH for Asset hierarchy)

    modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
        b.HasDiscriminator<string>("Discriminator")
          .HasValue("Asset"); // base
    });
    modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b => {
        b.ToTable("Asset", "irby").HasDiscriminator().HasValue("Computer");
    });
    // … similarly for MobileDevice, DeskPhone, etc.
    

💡 Usage & Examples

Applying the Migration

  1. Add the migration (already done):
    dotnet ef migrations add AddNewColumnDocumentImageTable
    
  2. Update the database:
    dotnet ef database update
    
  3. Inspect BuildTargetModel in the .Designer.cs to verify the new columns.

Command‑Line Snippets

# List pending migrations
dotnet ef migrations list

# Scaffold new migration
dotnet ef migrations add YourMigrationName

# Apply migrations to SQL Server
dotnet ef database update --context IrbyContext

📊 UML Diagram (Mermaid)

classDiagram
    class DocumentImage {
      <<Entity>>
      +Guid DocumentImageId
      +string FileName
      +string ContentType
      +DateTime DocumentUploadedDate
      +byte[] ImageContents
      +byte[] ImageOCRContents
      +string ImageOCRText
      +bool IsLegalDocument
      +bool IsDeleted
      +int Page
      +int TotalPages
      +Guid ReferenceId
      +Guid OriginalReferenceId
    }

🏁 Conclusion

This auto‑generated designer file captures the full EF Core model after the AddNewColumnDocumentImageTable migration. It ensures:

  • Consistency: EF knows exactly which columns exist and their types.
  • Future Migrations: Subsequent Add-Migration commands compare your current model to this snapshot.

Tip: Always commit both the migration .cs and its .Designer.cs & model snapshot files to source control for reliable migrations across teams.


Enjoy building with EF Core & keep your migrations safe! 🚀