📑 Migration Documentation: 20230706142626_NewIsLegalDocumentColumnDocumentCategory.Designer.cs

Location: IrbyImaging.DbContext/Migrations/20230706142626_NewIsLegalDocumentColumnDocumentCategory.Designer.cs
Purpose: Snapshot of the EF Core model after adding a new boolean column IsLegalDocument to the DocumentCategory entity.


🚀 Table of Contents

  1. Overview & Purpose
  2. EF Core Migrations Primer
  3. Key Functional Areas
  4. Dependencies & Technologies
  5. Data Models Snapshot
  6. How It Works
  7. Usage & Code Snippets
  8. UML Diagram (Partial)
  9. Conclusion & Next Steps

🔍 1. Overview & Purpose

This .Designer.cs file is an auto‑generated snapshot of the Entity Framework Core model at the time of applying the migration
NewIsLegalDocumentColumnDocumentCategory. Its primary responsibilities are:

  • Reconstructing the ModelBuilder configuration to match the current domain model.
  • Ensuring EF Core knows how to build the target schema (tables, columns, keys, relationships).
  • Capturing the addition of IsLegalDocument to DocumentCategory.

💡 Note: You should not manually edit this file. Use migrations to evolve your model instead.


🛠️ 2. EF Core Migrations Primer

Entity Framework Core Migrations provide:

  • Schema Evolution: Add/remove columns, tables, constraints.
  • Version Control: Each migration is timestamped (e.g., 20230706142626_...).
  • Snapshot Comparison: EF compares the previous snapshot to your current domain model to scaffold changes.

There are three key files per migration:

File Role
*.cs (Migration class) Contains Up()/Down() logic
*.Designer.cs (This file) Model snapshot for comparisons
*.resx Localization resources (rarely used)

🔑 3. Key Functional Areas

  1. Model Annotations
    • Sets global annotations (e.g., SQL Server version, identity columns).
  2. Entity Configurations
    • Defines entities, properties, keys, indexes, relationships.
  3. Discriminator Mapping
    • Configures Table‑Per‑Hierarchy (TPH) for Asset subtypes.
  4. New Column Capture
    • Highlights the newly added boolean property in DocumentCategory.

📦 4. Dependencies & Technologies

  • .NET 7.0
  • Entity Framework Core 7.0.7
  • SQL Server (via Microsoft.EntityFrameworkCore.SqlServer)
  • Domain Classes under IrbyImaging.DomainClasses

🧩 5. Data Models Snapshot

Below are highlights of the domain entities as captured in the snapshot. We’ve grouped the most relevant ones around document management.

📂 DocumentCategory (with new column)

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

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

    b.Property<DateTime>("AddedDate")
      .HasColumnType("datetime2");

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

    b.Property<bool>("IsAvailable")
      .HasColumnType("bit");

    b.Property<bool>("IsDeleted")
      .HasColumnType("bit");
    
    // 🆕 Newly added property
    b.Property<bool>("IsLegalDocument")
      .HasColumnType("bit");

    b.Property<bool>("IsSafety")
      .HasColumnType("bit");

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

    b.Property<DateTime>("ModifiedDate")
      .HasColumnType("datetime2");

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

    b.HasKey("Id");
    b.ToTable("DocumentCategory", "irby");
});
  • IsLegalDocument:
    • Type: bool (bit in SQL Server)
    • Purpose: Flag a document category as "legal" for downstream filtering/processing.

🔦 Snapshot Highlights

Entity Notes
DocumentAttribute Also has IsLegalDocument for attribute‑level tagging.
DocumentImage Stores document blobs, OCR data, plus IsLegalDocument and IsSafety flags.
TempDocumentData Staging table for incoming docs, including IsLegalDocument.
Toners, Jobs, Assets… Over 40+ domain classes configured (Assets, Employees, Jobs, Tickets, etc.).

These configurations ensure referential integrity, indexes on unique fields (e.g., IMEI, JdeNumber), and TPH inheritance for assets.


⚙️ 6. How It Works

  1. BuildTargetModel(...)

    • Called by EF Core during dotnet ef database update.
    • Replays all the modelBuilder configuration to reconstruct the model.
  2. Migration Application

    • EF Core compares the previous snapshot to this target snapshot.
    • Detects the addition of DocumentCategory.IsLegalDocument.
    • Generates SQL in the Up() method of the migration to ALTER TABLE ... ADD IsLegalDocument bit NOT NULL DEFAULT 0.
  3. Rolling Back

    • The Down() method would drop the column if rolling back the migration.

📝 7. Usage & Code Snippets

Applying the Migration

# Add migration (already done):
dotnet ef migrations add NewIsLegalDocumentColumnDocumentCategory 

# Update database:
dotnet ef database update
using var context = new IrbyContext();

// Fetch only legal categories
var legalCategories = context.DocumentCategories
    .Where(dc => dc.IsLegalDocument)
    .OrderBy(dc => dc.Name)
    .ToList();

📊 8. UML Diagram (Partial)

@startuml
class DocumentCategory {
  + Guid Id
  + string Name
  + string Description
  + bool IsAvailable
  + bool IsDeleted
  + bool IsSafety
  + bool IsLegalDocument   << New >>
  + DateTime AddedDate
  + string AddedBy
  + DateTime ModifiedDate
  + string ModifiedBy
}
DocumentCategory ..> DocumentType : 1..*
DocumentCategory ..> DocumentAttribute : 1..*
@enduml

Use PlantUML to render the above class diagram showing the new IsLegalDocument property.


✅ 9. Conclusion & Next Steps

  • Auto‑generated snapshot ensures EF Core knows the target schema.
  • IsLegalDocument enables new business logic (e.g., compliance workflows or legal dashboards).
  • After applying this migration, you can:
    • Update UI/Forms to toggle "Legal Document" status.
    • Implement filter/authorization logic based on the new flag.

🎉 Congratulations! Your database is now primed to distinguish legal vs. non‑legal document categories at scale.