πŸ“‹ Table of Contents

  1. Overview & Purpose
  2. Migration Responsibility
  3. Dependencies & Technologies
  4. Key Functional Areas
  5. Generated Model Snapshot
  6. Entity Relationship Diagram (UML)
  7. Using the Migration
  8. Sample Code Blocks
  9. Conclusion & Best Practices

1. Overview & Purpose πŸš€

This file:
IrbyImaging.DbContext/Migrations/20230620124309_AddIndexTagColumnToDocumentImage.Designer.cs
is an auto-generated EF Core migration snapshot. It captures the entire database model at the moment you ran:

dotnet ef migrations add AddIndexTagColumnToDocumentImage

Its primary purpose is to let Entity Framework Core compute the differences between your current model and the next migration. In particular, this migration adds a new column IndexTag to the DocumentImage table in the irby schema.

Note: You should never modify .Designer.cs files by handβ€”they are regenerated whenever you add or remove migrations.


2. Migration Responsibility πŸ”„

  • Name: AddIndexTagColumnToDocumentImage
  • DbContext: IrbyContext
  • Timestamp: 2023-06-20T12:43:09
  • Operation:
    1. Detect schema changes (new property on domain class).
    2. Generate SQL to ALTER TABLE and ADD COLUMN.
    3. Maintain a snapshot of the entire EF Core model for future diffs.

3. Dependencies & Technologies βš™οΈ

Technology Version / Notes
.NET SDK 7.0.7 (ProductVersion)
Entity Framework Core (EF Core) Microsoft.EntityFrameworkCore, Migrations, Metadata
Database Provider Microsoft.EntityFrameworkCore.SqlServer
C# Language C# 10+ (.NET 7)
UML / Diagramming (Mermaid) For class diagrams

4. Key Functional Areas πŸ—‚οΈ

  1. Model Annotations
    • ProductVersion
    • Relational:MaxIdentifierLength
  2. Identity Columns Configuration
    • UseIdentityColumns() globally
    • UseIdentityColumn() for specific properties
  3. Entities & Properties
    • All domain classes (Asset, DocumentImage, Employee, etc.)
  4. Indexes & Keys
    • Primary keys (HasKey)
    • Foreign keys (HasForeignKey)
    • Unique indexes (IsUnique())
    • Standard indexes (HasIndex)
  5. Inheritance (TPH)
    • Discriminator column for Asset hierarchy
  6. Schema & Table Mapping
    • Default schema: "irby"
    • Some tables without explicit schema

5. Generated Model Snapshot πŸ“

Below is a high‑level view of how EF Core reconstructs the model using ModelBuilder. The most important snippet is the DocumentImage entity where IndexTag was added.

DocumentImage Entity & IndexTag Addition

modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
    // Primary key
    b.HasKey("DocumentImageId")
     .HasName("PrimaryKey_DocumentImageId");

    // Table mapping
    b.ToTable("DocumentImage", "irby");

    // Existing columns
    b.Property<Guid>("DocumentImageId").HasColumnType("uniqueidentifier");
    b.Property<string>("FileName").HasColumnType("nvarchar(max)");
    b.Property<byte[]>("ImageContents").HasColumnType("varbinary(max)");
    // ... many other columns omitted for brevity ...

    // πŸ‘‰ Newly added column in this migration
    b.Property<string>("IndexTag")
     .HasColumnType("nvarchar(max)");

    // Other existing columns
    b.Property<bool>("IsLegalDocument").HasColumnType("bit");
    b.Property<int>("Page").HasColumnType("int");
    // ... etc ...
});

What Changed?

  • IndexTag (type nvarchar(max)) was not present before.
  • This migration ensures the database column is created.

Other Entities at a Glance

Entity Table Name Schema Notes
Asset Asset irby TPH hierarchy with Discriminator
AssetModel AssetModel irby FK β†’ Manufacturer (MakeId)
AssetHistory AssetHistory irby Audit history
DocumentAttribute DocumentAttribute irby Document metadata definitions
DocumentCategory DocumentCategory irby
DocumentType DocumentType irby
Employee Employee irby Unique index on JdeNumber
FieldOffice FieldOffice irby Multiple FKs to Employee
… … … Many other domain classes (Job, Customer, Ticket, IPMMigration, etc.)

6. Entity Relationship Diagram (UML) 🎨

Below is a simplified Mermaid diagram highlighting the DocumentImage and its relationship to an imaginary DocumentCategory entity.

classDiagram
  class DocumentImage {
    +Guid DocumentImageId
    +string FileName
    +string IndexTag
    +int Page
    +bool IsLegalDocument
    // ... other props
  }

  class DocumentCategory {
    +Guid Id
    +string Name
    +string Description
  }

  DocumentImage --> DocumentCategory : DocumentCategoryId

Tip: You can convert this snippet using any Mermaid Live Editor to get a visual diagram.


7. Using the Migration πŸ› οΈ

  1. Define the new property in your domain class (DocumentImage):

    namespace IrbyImaging.DomainClasses
    {
        public class DocumentImage
        {
            public Guid DocumentImageId { get; set; }
            // … existing props …
            public string IndexTag { get; set; }    // πŸ“Œ newly added
        }
    }
    
  2. Add a migration:

    dotnet ef migrations add AddIndexTagColumnToDocumentImage
    
  3. Inspect & commit the two generated files:

    • 20230620124309_AddIndexTagColumnToDocumentImage.cs
    • 20230620124309_AddIndexTagColumnToDocumentImage.Designer.cs
  4. Update the database:

    dotnet ef database update
    

8. Sample Code Blocks πŸ“¦

BuildTargetModel Snippet

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    #pragma warning disable 612, 618

    // Global annotations
    modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    // Enable SQL Server identity columns
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // … entity definitions …
    modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
    {
        b.Property<string>("IndexTag").HasColumnType("nvarchar(max)");
        // … rest …
    });

    #pragma warning restore 612, 618
}

Applying the Migration in Code

# Add migration
dotnet ef migrations add AddIndexTagColumnToDocumentImage

# Inspect changes
git diff Migrations/20230620124309_AddIndexTagColumnToDocumentImage.*

# Apply to local DB
dotnet ef database update

9. Conclusion & Best Practices βœ…

  • Keep migrations small & focused: One schema change per migration.
  • Review auto-generated code: Ensure the snapshot represents your intended model.
  • Commit both .cs & .Designer.cs: They work together.
  • Never hand-edit generated files. Change your domain classes and re-scaffold.
  • Use CI/CD pipelines to apply migrations automatically on staging/production.

✨ With this migration in place, you can now store and query an IndexTag for each document image, enabling richer search, categorization, or OCR workflows in your imaging application.


Happy coding! πŸš€