πŸ“‘ Migration Documentation: 20240523153517_AddAccountingDocumentType.Designer.cs


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Model Changes
  5. BuildTargetModel Method Breakdown
  6. Usage & Examples
  7. Mermaid UML Diagram
  8. Conclusion

Overview & Purpose

πŸš€ Migration Name: AddAccountingDocumentType
πŸ“… Timestamp: 20240523153517
πŸ“ File: AddAccountingDocumentType.Designer.cs

This auto-generated EF Core Designer file captures the state of the database model after applying the AddAccountingDocumentType migration. Its primary purpose is to:

  • Define the target model structure (via BuildTargetModel) which EF Core uses to compute future migrations.
  • Document the addition of the new AccountingDocumentType column on the DocumentImage table.

Tip: Designer files should not be manually editedβ€”they are regenerated on each migration scaffold.


Dependencies & Technologies

Technology / Package Version Role
Microsoft.EntityFrameworkCore v7.0.7 Core ORM framework
Microsoft.EntityFrameworkCore.SqlServer v7.0.7 SQL Server provider
Microsoft.EntityFrameworkCore.Design v7.0.7 Design-time tooling (migrations, scaffolding)
.NET 7 β€” Target framework

Key Functional Areas

  • Model Snapshot
    Captures all DbSet<TEntity> configurations after migration.

  • Schema Annotations

    • HasAnnotation("ProductVersion", "7.0.7")
    • UseIdentityColumns for SQL Server identity properties.
  • Entity Mappings
    Configures tables, columns, primary keys, indexes, relationships, discriminators (TPH inheritance).

  • New Column
    Introduction of AccountingDocumentType to the DocumentImage entity.


Data Model Changes

DocumentImage Entity

This migration adds a new property:

Column Name CLR Type SQL Type Nullable Comments
AccountingDocumentType Guid uniqueidentifier No πŸ’Ό Tracks the accounting doc type ID

Before this migration, the DocumentImage table already had other document-type GUIDs:

  • ITDocumentType
  • HRDocumentType
  • SafetyDocumentType
  • LegalDocumentType

Now it also stores an AccountingDocumentType, enabling specialized indexing and filtering.


BuildTargetModel Method Breakdown

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

    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // … (ALL entities mapping) …

    modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
    {
        b.Property<Guid>("DocumentImageId")
            .HasColumnType("uniqueidentifier");

        b.Property<Guid>("AccountingDocumentType")              // ← NEW PROPERTY
            .HasColumnType("uniqueidentifier");

        b.Property<Guid>("HRDocumentType")
            .HasColumnType("uniqueidentifier");

        b.Property<Guid>("ITDocumentType")
            .HasColumnType("uniqueidentifier");

        b.Property<Guid>("LegalDocumentType")
            .HasColumnType("uniqueidentifier");

        b.Property<Guid>("SafetyDocumentType")
            .HasColumnType("uniqueidentifier");

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

        // … other existing columns …

        b.HasKey("DocumentImageId")
            .HasName("PrimaryKey_DocumentImageId");

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

    // … (relationships, other entity configurations) …
}
  • Property<Guid>("AccountingDocumentType")
    Creates a non-nullable uniqueidentifier column named AccountingDocumentType.
  • Table Schema: irby.DocumentImage

Usage & Examples

Applying the Migration

  1. Scaffold Migration

    dotnet ef migrations add AddAccountingDocumentType
    
  2. Update Database

    dotnet ef database update
    

    This will execute the SQL to add the new column.

Querying with the New Property

using (var context = new IrbyContext())
{
    // Create new DocumentImage with accounting type
    var accountingTypeId = Guid.Parse("AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE");
    var docImage = new DocumentImage
    {
        DocumentImageId = Guid.NewGuid(),
        AccountingDocumentType = accountingTypeId,
        DocumentUploadedDate = DateTime.UtcNow,
        // … set other required props …
    };

    context.DocumentImages.Add(docImage);
    context.SaveChanges();

    // Query by accounting document type
    var accountingDocs = context.DocumentImages
        .Where(d => d.AccountingDocumentType == accountingTypeId)
        .ToList();

    Console.WriteLine($"Found {accountingDocs.Count} accounting documents.");
}

Mermaid UML Diagram

classDiagram
    class DocumentImage {
        <<Entity>>
        +Guid DocumentImageId
        +Guid HRDocumentType
        +Guid ITDocumentType
        +Guid LegalDocumentType
        +Guid SafetyDocumentType
        +Guid AccountingDocumentType     <-- New
        +bool IsAccounting
        +string FileName
        +DateTime DocumentUploadedDate
        +byte[] ImageContents
        // … other properties …
    }

    DocumentImage : Table = irby.DocumentImage

Conclusion

🎯 What We Achieved

  • Added a new GUID column (AccountingDocumentType) to facilitate accounting-focused document categorization.
  • Captured the complete target model snapshot post-migration, ensuring accurate future diffs.

πŸ”§ Next Steps

  • Update any UI forms or API endpoints that should allow setting or filtering by AccountingDocumentType.
  • Write or update unit/integration tests to cover the new property.
  • Ensure indexes are created (via subsequent migrations) if you anticipate high-query loads on AccountingDocumentType.

Happy Coding! πŸŽ‰