📋 Documentation: 20220614182210_NewColumnDocumentImageTable2.Designer.cs

Assembly: IrbyImaging.DbContext
Namespace: IrbyImaging.DbContext.Migrations
Generated: 06‑14‑2022
Author: kvamshi


📑 Table of Contents

  1. Overview & Purpose
  2. Migration Class Metadata
  3. Key Functional Areas
  4. Entities & Data Models
  5. Relationships & Associations
  6. Dependencies & Technologies
  7. EF Core Migration Workflow
  8. Code Snippets & Examples
  9. UML Class Diagram
  10. Conclusion

1. Overview & Purpose

This file is the designer portion of an Entity Framework Core migration named 20220614182210_NewColumnDocumentImageTable2. While the main migration class (in NewColumnDocumentImageTable2.cs) contains the Up()/Down() methods, the .Designer.cs file houses the model snapshot after the migration runs. EF Core uses this snapshot to understand how your .NET domain classes map to your relational schema—and to compute deltas for future migrations.

✨ Highlights:

  • Captures the entire object‑relational mapping for all entities in the IrbyContext.
  • Ensures EF Core can reverse or reapply the migration consistently.
  • Auto‑generated; manual edits are not recommended.

2. Migration Class Metadata

[DbContext(typeof(IrbyContext))]
[Migration("20220614182210_NewColumnDocumentImageTable2")]
partial class NewColumnDocumentImageTable2 : Migration
{
    // ...
}
Attribute Description
[DbContext] Targets the IrbyContext EF DbContext
[Migration("20220614182210_…")] Unique identifier/timestamp for the migration
partial class NewColumn… : Migration Inherits EF Core’s Migration base class

3. Key Functional Areas

3.1 BuildTargetModel Method

Signature:
protected override void BuildTargetModel(ModelBuilder modelBuilder)

  • Purpose: Defines the complete EF Core model after this migration.
  • Mechanism:
    1. Adds global annotations (e.g. SQL Server generation strategy)
    2. Configures each entity’s properties, keys, indexes, table names, schemas.
    3. Establishes relationships (HasOne, WithMany, ForeignKey, OnDelete).

🔧 Why It Matters: When EF generates the next migration, it compares this snapshot to the current model in your codebase to detect additions, removals or modifications.


4. Entities & Data Models

Below is a condensed table of the primary entities configured in this migration.

Entity Class Table (Schema) Key Notable Columns
Asset irby.Asset Id (GUID) Category, Discriminator, PurchaseDate, SerialNumber
AssetHistory irby.AssetHistory Id (GUID) AssetId, Action, Timestamp
AssetModel irby.AssetModel Id (int) Name, MakeId
AssetModelDetail AssetModelDetail Id (int) AssetModelId, MakeId, Category
DocumentImage irby.DocumentImage DocumentImageId (GUID) ImageContents, ImageOCRText, IsLegalDocument
Employee irby.Employee Id (GUID) JdeNumber (unique), Status
FieldOffice irby.FieldOffice Id (GUID) JdeNumber (unique), ManagerId
OperatingSystem irby.OperatingSystem Id (int) Name
Ticket irby.Ticket Id (GUID) TicketNumber, Status
Update irby.Update Id (GUID) TicketId, Timestamp, UpdatedBy
…plus many more (CarrierType, GeneralLedger, ODS*, IPMMigration, etc.)_

📘 Note: All tables live under the irby schema unless otherwise noted.


5. Relationships & Associations

Principal Entity Navigation Property Dependent Entity FK Column Delete Behavior
Asset FieldOffice FieldOffice FieldOfficeId Default (ClientSetNull)
Asset Model AssetModel ModelId Cascade
Asset Owner Employee OwnerId Default
AssetModel Make Manufacturer MakeId Cascade
AssetModelDetail AssetModel AssetModel AssetModelId Default
AssetModelDetail Make Manufacturer MakeId Cascade
Employee CurrentJob Job CurrentJobId Cascade
FieldOffice Manager / ProjectManager / Superintendent Employee ManagerId etc. Default
Computer OperatingSystem OperatingSystem OperatingSystemId Cascade
SafetyEquipment OperatingSystem OperatingSystem OperatingSystemId Cascade
Ticket Updates Update TicketId Cascade
… … … … …

🔗 Tip: Examine the modelBuilder.Entity(...).HasOne(...).WithMany(...) calls in BuildTargetModel to discover all relationships.


6. Dependencies & Technologies

  • .NET 5.0.12 & C# 9
  • Entity Framework Core 5.0
  • SQL Server as RDBMS (annotations like SqlServer:ValueGenerationStrategy)
  • EF Core Migrations API (Migration, ModelBuilder, ModelSnapshot)

7. EF Core Migration Workflow

7.1 Adding a Migration

# From the project root:
dotnet ef migrations add NewColumnDocumentImageTable2 \
    --context IrbyContext \
    --output-dir Migrations
  • This generates two files:
    • 20220614182210_NewColumnDocumentImageTable2.cs (Up/Down logic)
    • 20220614182210_NewColumnDocumentImageTable2.Designer.cs (model snapshot)

7.2 Applying / Rolling Back

# Apply pending migrations
dotnet ef database update

# Rolling back to a previous migration
dotnet ef database update 20220614170000_PreviousMigration

8. Code Snippets & Examples

8.1 Mapping DocumentImage

modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
    b.Property<Guid>("DocumentImageId")
     .HasColumnType("uniqueidentifier");
    b.Property<byte[]>("ImageContents")
     .HasColumnType("varbinary(max)");
    b.Property<string>("ImageOCRText")
     .HasColumnType("nvarchar(max)");
    b.Property<bool>("IsLegalDocument")
     .HasColumnType("bit");
    // … more properties …
    b.HasKey("DocumentImageId")
     .HasName("PrimaryKey_DocumentImageId");
    b.ToTable("DocumentImage", "irby");
});

8.2 Global Annotations

modelBuilder
    .HasAnnotation("Relational:MaxIdentifierLength", 128)
    .HasAnnotation("ProductVersion", "5.0.12")
    .HasAnnotation("SqlServer:ValueGenerationStrategy", 
                   SqlServerValueGenerationStrategy.IdentityColumn);

9. UML Class Diagram

classDiagram
    class Asset {
      +Guid Id
      +string Category
      +DateTimeOffset PurchaseDate
    }
    class AssetModel {
      +int Id
      +string Name
    }
    class Manufacturer {
      +int Id
      +string Name
    }
    AssetModel --> Manufacturer : MakeId
    Asset --> AssetModel : ModelId
    Asset --> Employee : OwnerId
    Employee --> Job : CurrentJobId
    class DocumentImage {
      +Guid DocumentImageId
      +byte[] ImageContents
      +bool IsLegalDocument
    }

👉 This diagram is a subset illustrating core entities & relationships.


🔚 Conclusion

This designer file is critical to EF Core’s migration infrastructure. It captures a snapshot of your model post‑migration, enabling:

  • 🚀 Next Migrations: Accurate diff computation
  • 🔄 Rollbacks: Consistent schema restoration
  • 📦 Team Collaboration: Safe version control of your database schema

Tip: Never manually edit the .Designer.cs file—changes should flow through your entity classes and Add-Migration commands.


Generated with care by EF Core’s migration tooling. Happy coding! 🎉