📑 20230606160443_AddReviewColumnToAsset.Designer.cs Documentation


🗂 Table of Contents

  1. Overview & Purpose
  2. Migration File Structure
  3. BuildTargetModel Method
  4. Key Entities & Model Snapshot
  5. Asset Entity & NeedsReview Column
  6. Inheritance & Discriminators
  7. Relationships & Navigation Properties
  8. Dependencies & Technologies
  9. Applying the Migration
  10. Sample Usage
  11. UML Diagram (Excerpt)
  12. Conclusion

1. Overview & Purpose

This file is the auto‐generated EF Core Designer for the migration AddReviewColumnToAsset. It captures the model snapshot—the full shape of your database schema—as understood by EF Core at the moment this migration was scaffolded. Its primary role is to:

  • Define all tables, columns, keys, indexes, relationships, discriminators, etc.
  • Include the newly added NeedsReview column on the Asset entity.
  • Support EF Core’s ability to compute diffs when you add or remove migrations.

Note: The actual DDL operations (e.g., SQL to add a column) are in the sibling file 20230606160443_AddReviewColumnToAsset.cs. The .Designer.cs file only builds the in‐memory model.


2. Migration File Structure

IrbyImaging.DbContext/
 └─ Migrations/
     ├─ 20230606160443_AddReviewColumnToAsset.cs       ← Up()/Down() methods
     └─ 20230606160443_AddReviewColumnToAsset.Designer.cs ← BuildTargetModel()
  • Up()/Down(): Contains the code to apply / revert the schema change.
  • Designer: Regenerates the full schema snapshot to detect future changes.

3. BuildTargetModel Method

protected override void BuildTargetModel(ModelBuilder modelBuilder) {
    #pragma warning disable 612, 618
    modelBuilder
        .HasAnnotation("Relational:MaxIdentifierLength", 128)
        .HasAnnotation("ProductVersion", "5.0.12")
        .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
    // … all entity configurations …
    #pragma warning restore 612, 618
}
  1. Annotations

    • MaxIdentifierLength: SQL Server max = 128.
    • ProductVersion: EF Core version.
    • ValueGenerationStrategy: Identity columns.
  2. Entity Configuration

    • Defines each entity’s columns, keys, indexes, table name and schema.
    • Configures inheritance via HasDiscriminator().
    • Sets up relationships with HasOne()/.WithMany().

4. Key Entities & Model Snapshot

EF Core scaffolded 30+ entities in namespace IrbyImaging.DomainClasses. Here is an excerpt:

Entity Table (Schema) PK Notes
Asset irby.Asset Id : uniqueidentifier Base class for all assets
AssetHistory irby.AssetHistory Id : uniqueidentifier Tracks changes to assets
AssetModel irby.AssetModel Id : int Models & their manufacturer FK
Computer (inherits Asset) irby.Asset Inherited from Asset Computers with OS FK
MobileDevice (inherits Asset) irby.Asset Inherited IMEI unique index, Carrier, SIM
Employee irby.Employee Id : uniqueidentifier Unique JdeNumber, CurrentJob FK
FieldOffice irby.FieldOffice Id : uniqueidentifier Manager, ProjectManager, Superintendent
Ticket irby.Ticket Id : uniqueidentifier Status, Type, TicketNumber
…and many more…

Tip: The EF Core CLI command dotnet ef migrations script will generate a complete migration SQL script based on this snapshot.


5. Asset Entity & NeedsReview Column

The key purpose of this specific migration is to add the NeedsReview flag to the Asset table:

modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
    b.Property<bool>("NeedsReview")
     .HasColumnType("bit");
    // … other properties …
});

Before Migration

  • Asset had columns: Id, Category, ModelId, OwnerId, Status, etc.

After Migration

  • New column NeedsReview (bit) to indicate if an asset requires manual review.
Column Type Nullable Description
NeedsReview bit false true → asset requires review

6. Inheritance & Discriminators

EF Core uses table‐per‐hierarchy (TPH) for all Asset subtypes:

b.HasDiscriminator<string>("Discriminator")
 .HasValue("Asset")
 .HasValue("Computer", "Computer")
 .HasValue("MobileDevice", "MobileDevice")
// … etc …
  • Column: Discriminator (nvarchar(max))
  • Subclasses: Computer, DeskPhone, Dock, Monitor, etc.

7. Relationships & Navigation Properties

EF Core configures FKs and navigations for you:

  • Asset → FieldOffice
    b.HasOne("FieldOffice","FieldOffice")
     .WithMany("Assets")
     .HasForeignKey("FieldOfficeId");
    
  • Asset → AssetModel (ModelId) (required)
  • Asset → Employee (OwnerId)
  • Employee → Job (CurrentJobId) (required)
  • Ticket → Update (TicketId)

 💡 All relationships use DeleteBehavior.Cascade except where explicitly left default.


8. Dependencies & Technologies

  • .NET 5.0
  • Entity Framework Core 5.0.12
  • SQL Server (via Microsoft.EntityFrameworkCore.SqlServer)
  • C# 9 (nullable-aware code suppressed)
  • ModelBuilder / Fluent API configurations

9. Applying the Migration

  1. Scaffold (already done):
    dotnet ef migrations add AddReviewColumnToAsset
    
  2. Apply to database:
    dotnet ef database update
    
    or generate SQL script:
    dotnet ef migrations script 0 20230606160443_AddReviewColumnToAsset
    

10. Sample Usage

// After updating the DB, you can filter assets requiring review:
var assetsToReview = context.Assets
    .Where(a => a.NeedsReview)
    .ToList();

11. UML Diagram (Excerpt)

@startuml
class Asset {
  +Guid Id
  +string Category
  +bool NeedsReview
  +string Status
  // …
}
class Computer
class MobileDevice
Asset <|-- Computer
Asset <|-- MobileDevice

class AssetModel {
  +int Id
  +string Name
}
Asset o-- AssetModel : ModelId
@enduml

12. Conclusion

This Designer file is an essential part of EF Core’s migration infrastructure. It represents the full schema snapshot of your domain model—including the newly added NeedsReview column on Asset—and enables EF Core to detect and apply schema changes safely.
Make sure to commit both the .cs and .Designer.cs files when checking in migrations to maintain consistency across environments.

Happy coding! 🚀