πŸ“„ Documentation: 20230802150235_AddNewColumnToDocumentImageTable.Designer.cs


πŸ—‚ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. File Structure & Annotations
  4. Key Functional Areas
    4.1 Migration Metadata
    4.2 Model Snapshot: BuildTargetModel
    4.3 Entity Configurations
    4.4 Relationships & Navigation
  5. Usage & Examples
  6. Simplified UML Diagram
  7. Conclusion

1. Overview & Purpose

What is this file?
This is an auto-generated Entity Framework Core (EF Core) Migration Designer file for the migration named
20230802150235_AddNewColumnToDocumentImageTable. It represents the model snapshot at this point in time.

🎯 Primary Purpose

  • Provide a snapshot of the entire EF Core model (entities, properties, relationships) after applying the AddNewColumnToDocumentImageTable migration.
  • Enable EF Core to calculate and apply subsequent migrations by comparing current model vs. this snapshot.

Note: You typically do not edit designer files by hand.


2. Dependencies & Technologies

Dependency Purpose
Microsoft.EntityFrameworkCore Core EF APIs for ModelBuilder, Migrations, Metadata
Microsoft.EntityFrameworkCore.Migrations Supports migration building and data seeding
Microsoft.EntityFrameworkCore.Metadata Defines annotations, conventions, mapping strategies
Microsoft.EntityFrameworkCore.Storage.ValueConversion Value converters (e.g. string ↔ enum)
C# 10 / .NET 7 Language & runtime for code generation

3. File Structure & Annotations

// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

#nullable disable

namespace IrbyImaging.DbContext.Migrations
{
    [DbContext(typeof(IrbyContext))]
    [Migration("20230802150235_AddNewColumnToDocumentImageTable")]
    partial class AddNewColumnToDocumentImageTable
    {
        /// <inheritdoc />
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            // ... entire model snapshot ...
        }
    }
}
  • [DbContext] attribute links this snapshot to your IrbyContext.
  • [Migration(...)] specifies the unique timestamp-based identifier.
  • BuildTargetModel overrides define the database schema.

4. Key Functional Areas

4.1 Migration Metadata

  • ProductVersion
    modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);
    
  • UseIdentityColumns
    Activates SQL Server identity behavior for auto-generated keys.
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
    

4.2 Model Snapshot: BuildTargetModel

  • Purpose: Reflects the entire EF Core model (all DbSet<T> entities) after this migration.
  • Mechanism:
    1. Entity declarations with modelBuilder.Entity("Namespace.Type", b => { ... }).
    2. Property mappings: .Property<type>("Name")
    3. Keys & Indices: .HasKey(), .HasIndex()
    4. Table mapping: .ToTable("TableName", "schema")
    5. Relationships: .HasOne(...).WithMany(...).HasForeignKey(...)

4.3 Entity Configurations

Below is a representative sampleβ€”the file configures dozens of entities. Here’s the snippet for the DocumentImage table (the target of this migration):

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

    // πŸ†• NEW COLUMN (added by this migration)
    b.Property<string>("NewColumnName")
     .HasColumnType("nvarchar(max)");

    // Existing columns
    b.Property<string>("FileName").HasColumnType("nvarchar(max)");
    b.Property<byte[]>("ImageContents").HasColumnType("varbinary(max)");
    b.Property<bool>("IsDeleted").HasColumnType("bit");
    // ... many others ...

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

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

πŸ”‘ Key Concepts

  • .Property<>() β†’ maps a CLR property to a database column.
  • .HasColumnType() β†’ specifies exact SQL type.
  • .HasKey() β†’ configures the primary key.
  • .ToTable() β†’ sets schema & table name.

4.4 Relationships & Navigation

All associations between domain classes are rebuilt in this snapshot. Example:

modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.Employee", "Owner")
     .WithMany("Assets")
     .HasForeignKey("OwnerId");
    // …
});
  • One‑to‑Many: .HasOne(...).WithMany(...)
  • Cascade delete rules and required constraints appear in .OnDelete(DeleteBehavior.Cascade) and .IsRequired() calls.

5. Usage & Examples

5.1 Common Commands

  • Add a new migration
    dotnet ef migrations add AddNewColumnToDocumentImageTable
    
  • Update database
    dotnet ef database update
    

5.2 What Happens Under the Hood

  1. EF Core generates two files:
    • 20230802150235_AddNewColumnToDocumentImageTable.cs (migration operations)
    • This file: .Designer.cs (model snapshot)
  2. When you call update, EF compares the current model (your code-first classes + OnModelCreating) against this snapshot to see what SQL operations to run.
  3. Designer file ensures EF knows the baseline schema.

6. Simplified UML Diagram

Below is a simplified class‑diagram fragment showing how entities relate. Only key parts are illustrated:

+----------------+       1      *       +----------------+
|   Employee     |----------------------|     Asset      |
+----------------+    Assets           +----------------+
| - EmployeeId   |                      | - Id          |
| - FirstName    |                      | - SerialNumber|
| - LastName     |                      | - ModelId     |
+----------------+                      +----------------+
  • Employee has many Asset
  • Asset references Employee via OwnerId

(The real model has dozens of tables; this is just an illustrative snippet.)


7. Conclusion

This Designer file is a critical piece of EF Core migrations, capturing your entire model at a given migration point.

  • ✏️ Do not edit manually β€” changes will be lost.
  • βœ… Use EF Core CLI or Package Manager Console to generate and apply migrations.
  • πŸ”§ Understand BuildTargetModel to troubleshoot advanced scenarios (e.g., customizing comments, schemas, conventions).

Thank you for reading! πŸš€ If you need to add, rollback, or inspect migrations, always refer to both the operations file (.cs) and its Designer snapshot.