πŸ“‘ Table of Contents

  1. πŸ“– Overview & Purpose
  2. πŸš€ Dependencies & Technologies
  3. πŸ—οΈ Key Functional Areas
  4. πŸ—ƒοΈ Data Models & Schema
  5. βš™οΈ Migration Intent – Adding IndexTag
  6. πŸ“‹ Sample Code Snippets
  7. πŸ–ΌοΈ UML Class Diagram
  8. πŸ“š Usage Examples
  9. 🎯 Conclusion

πŸ“– Overview & Purpose

File:

IrbyImaging.DbContext/
 └── Migrations/
     └── 20230619190753_AddIndexTagColumn.Designer.cs

This auto-generated Designer file is part of an Entity Framework Core migration named AddIndexTagColumn. It contains the target model snapshotβ€”i.e. the BuildTargetModel(ModelBuilder) methodβ€”which describes the complete database schema after this migration is applied.

Why it exists:

  • Enables EF Core to compute diffs when creating future migrations.
  • Serves as a blueprint for the IrbyContext model.
  • Ensures consistency between your C# classes and the SQL database schema.

πŸš€ Dependencies & Technologies

  • .NET & C# (β‰₯ .NETΒ 7.0, C#Β 11)
  • Entity Framework Core 7.0.7
  • Microsoft.EntityFrameworkCore.SqlServer
  • SQL Server (relational database provider)

πŸ—οΈ Key Functional Areas

  1. Global Annotations & Identity Setup

    • .HasAnnotation("ProductVersion", "7.0.7")
    • .HasAnnotation("Relational:MaxIdentifierLength", 128)
    • SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
  2. Entity Configurations

    • ~30 domain classes (e.g., Asset, Employee, Job)
    • TPH (Table‐Per‐Hierarchy) for Asset subtypes (Computer, DeskPhone, MobileDevice, etc.)
    • Column types, lengths, required/nullable flags
  3. Indexes & Constraints

    • Unique indexes (e.g., Employee.JdeNumber)
    • Filtered indexes for nullable columns
    • Foreign key indexes for relationships
  4. Relationships & Navigation

    • One‑to‑many & many‑to‑one mappings
    • Cascade delete behaviors
    • Fluent API navigation registrations

πŸ—ƒοΈ Data Models & Schema

Below is a condensed view of some of the primary entities, their tables, keys, and the new IndexTag column:

Entity Class Table (Schema) Primary Key Notes
TempDocumentData πŸ‘ˆ New irby.TempDocumentData TempDocumentDataId : uniqueidentifier + IndexTag (nvarchar(max))
Asset irby.Asset Id : uniqueidentifier TPH with discriminator
AssetModel irby.AssetModel Id : int (Identity) FK β†’ Manufacturer
Employee irby.Employee Id : uniqueidentifier Unique index on JdeNumber
Job irby.Job Id : uniqueidentifier Unique index on JdeNumber
FieldOffice irby.FieldOffice Id : uniqueidentifier Unique index on JdeNumber
… … … …

Tip: This file configures all domain classes under the IrbyImaging.DomainClasses namespace.


βš™οΈ Migration Intent – Adding IndexTag

The heart of this migration is to introduce a new metadata column, IndexTag, onto the TempDocumentData table. This allows temporary documents to carry a custom tag for indexing or categorization.

What changed?

  • Up() adds the column:
    migrationBuilder.AddColumn<string>(
        name: "IndexTag",
        schema: "irby",
        table: "TempDocumentData",
        type: "nvarchar(max)",
        nullable: true);
    
  • Down() removes it:
    migrationBuilder.DropColumn(
        name: "IndexTag",
        schema: "irby",
        table: "TempDocumentData");
    

Snapshot in Designer

modelBuilder.Entity("IrbyImaging.DomainClasses.TempDocumentData", b =>
{
    b.Property<Guid>("TempDocumentDataId")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");

    // … other properties …

    b.Property<string>("IndexTag")
     .HasColumnType("nvarchar(max)");    // ← New

    b.ToTable("TempDocumentData", "irby");
});

πŸ“‹ Sample Code Snippets

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    // 1. Global annotations
    modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    // 2. Identity columns for SQL Server
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // 3. Configure TempDocumentData
    modelBuilder.Entity("IrbyImaging.DomainClasses.TempDocumentData", b =>
    {
        b.Property<Guid>("TempDocumentDataId")
         .ValueGeneratedOnAdd()
         .HasColumnType("uniqueidentifier");

        // ← Newly added column
        b.Property<string>("IndexTag")
         .HasColumnType("nvarchar(max)");

        // … other columns …

        b.ToTable("TempDocumentData", "irby");
    });

    // 4. Configure other entities…
}

Defining a Unique Index

modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
    b.HasIndex("JdeNumber")
     .IsUnique()
     .HasFilter("[JdeNumber] IS NOT NULL");
});

πŸ–ΌοΈ UML Class Diagram

classDiagram
    Asset <|-- Computer
    Asset <|-- DeskPhone
    Asset <|-- Dock
    Asset <|-- MobileDevice
    Asset <|-- Monitor
    Asset <|-- NetworkEquipment
    Asset <|-- OfficePrinter
    Asset <|-- Printer
    Asset <|-- SafetyEquipment

    AssetModelDetail --|> AssetModel
    AssetModel --> Manufacturer : Make
    Asset --> AssetModel : Model
    Asset --> FieldOffice : FieldOffice
    Asset --> Employee : Owner

    Computer --> OperatingSystem : OperatingSystem
    SafetyEquipment --> OperatingSystem : OperatingSystem

πŸ“š Usage Examples

1. Reading the IndexTag

using var db = new IrbyContext();
var temp = db.TempDocumentData.FirstOrDefault();
Console.WriteLine($"IndexTag: {temp?.IndexTag}");

2. Updating the IndexTag

var doc = db.TempDocumentData.Find(myId);
doc.IndexTag = "Invoice-2023-07";
await db.SaveChangesAsync();

3. Filtering by IndexTag

var invoices = db.TempDocumentData
    .Where(d => d.IndexTag.StartsWith("Invoice-"))
    .ToList();

🎯 Conclusion

This Designer snapshot is a vital part of the EF Core migration pipeline. By defining the IndexTag column addition in TempDocumentData, it empowers the application to classify and search temporary documents more efficiently. Keep this file in sync with your domain model; any manual edits can break future migrations.

βœ… Tip: Always review auto-generated designer files to ensure that EF Core’s snapshot matches your intent and domain classes.