πŸ“¦ IrbyImaging.DbContext/Migrations/20240306145546_AddColumnsToEquipment.Designer.cs Documentation


πŸ“‘ Table of Contents

  1. Overview & Purpose πŸš€
  2. File Structure & Location πŸ“‚
  3. Dependencies & Technologies πŸ”—
  4. Key Functional Areas πŸ”
  5. Entities Affected ✏️
  6. New Columns on Equipment βž•
  7. How EF Core Migrations Work πŸ—οΈ
  8. Code Snippets & Examples πŸ’»
  9. UML Diagram πŸ“Š
  10. Conclusion 🎯

1. Overview & Purpose πŸš€

AddColumnsToEquipment.Designer.cs is an auto-generated EF Core migration designer file. It represents the target model snapshot for the migration named 20240306145546_AddColumnsToEquipment.

  • Purpose:
    • Capture the final Entity‐Framework model after applying the migration that adds new β€œremarks” columns to the Equipment table.
    • Enable EF Core to compare schemas and generate SQL to bring the database in line with the code model.

2. File Structure & Location πŸ“‚

IrbyImaging.DbContext/
└─ Migrations/
   β”œβ”€ 20240306145546_AddColumnsToEquipment.cs       ← Migration logic
   └─ 20240306145546_AddColumnsToEquipment.Designer.cs  ← Model snapshot
  • Designer file: Contains BuildTargetModel(ModelBuilder modelBuilder), which fully configures all entities, their properties, relationships, and database mappings after the migration is applied.

3. Dependencies & Technologies πŸ”—

Technology / Library Version Role
Microsoft.EntityFrameworkCore 7.0.7 ORM for .NET β†’ model building & migrations
Microsoft.EntityFrameworkCore.SqlServer 7.0.x SQL Server provider; uses identity columns
.NET 6 / .NET 7 SDK N/A Target framework

Note: This file is auto‑generated by the dotnet ef migrations add command.


4. Key Functional Areas πŸ”

  1. [DbContext(typeof(IrbyContext))]
    Marks that this snapshot belongs to the IrbyContext.

  2. [Migration("20240306145546_AddColumnsToEquipment")]
    Associates this snapshot with the AddColumnsToEquipment migration applied at 2024-03-06 14:55:46.

  3. BuildTargetModel(ModelBuilder modelBuilder)

    • Configures all entities (Asset, Employee, Equipment, …)
    • Maps CLR types β†’ database tables, columns, keys, indexes, relationships
    • Applies TphMappingStrategy for certain hierarchies (e.g., Asset β†’ Computer, MobileDevice, etc.)

5. Entities Affected ✏️

While the snapshot covers hundreds of tables and views, the focus of this migration is the Equipment entity.
Below is a condensed view of the pre-existing vs post‑migration properties.


6. New Columns on Equipment βž•

This migration adds two new properties to the Equipment table:

Column Name CLR Type SQL Type Nullable Description
AssetRemark string nvarchar(max) βœ”οΈ Additional free-form remark on equipment.
AssetRemark2 string nvarchar(max) βœ”οΈ Secondary remark field for equipment notes.

Before

modelBuilder.Entity<Equipment>(b => {
    b.Property<Guid>("EquipmentId").ValueGeneratedOnAdd();
    b.Property<string>("SerialNumber");
    b.Property<string>("CurrentStatus");
    // … other existing props …
});

After

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

    // … existing properties …

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

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

    // … remaining properties …

    b.HasKey("EquipmentId");
    b.ToTable("Equipment", "irby");
});

7. How EF Core Migrations Work πŸ—οΈ

  1. Design-Time Snapshot

    • EF Core keeps a model snapshot (in .Designer.cs) of your DbContext after each migration.
  2. Comparisons

    • When you run dotnet ef migrations add XYZ, EF Core:
      • Compares your current model in code vs. the last snapshot.
      • Detects differences (e.g., new properties).
  3. Generating Migration Files

    • Creates two files:
      • 20240306145546_AddColumnsToEquipment.cs β†’ Contains Up()/Down() SQL operations.
      • 20240306145546_AddColumnsToEquipment.Designer.cs β†’ New snapshot after changes.
  4. Applying Migrations

    • On dotnet ef database update, EF runs the Up() steps and replaces the snapshot with this Designer.

8. Code Snippets & Examples πŸ’»

Registering Migrations in Startup.cs

services.AddDbContext<IrbyContext>(options => 
    options.UseSqlServer(Configuration.GetConnectionString("IrbyDb")));

Adding the Migration

# In Package Manager Console:
dotnet ef migrations add AddColumnsToEquipment
# This produces both .cs and .Designer.cs files

Updating Database

dotnet ef database update

9. UML Diagram πŸ“Š

classDiagram
    class Equipment {
      +Guid EquipmentId
      +string AssetNumber
      +string AssetManufacturer
      +string SerialNumber
      +string CurrentStatus
      +string AssetRemark      <<new>>
      +string AssetRemark2     <<new>>
      +DateTime? DateAcquired
      +DateTime? DateDisposed
      // … other props …
    }

    class Job {
      +Guid JobId
      +string Name
      // …
    }

    Equipment --> Job : JobId (FK)
  • Note: Equipment.JobId is a required foreign key β†’ each Equipment belongs to one Job.

10. Conclusion 🎯

  • AddColumnsToEquipment.Designer.cs is a snapshot of your EF model after adding two new remark fields to the Equipment entity.
  • It is critical for EF Core to track schema changes, generate diff scripts, and ensure your database stays in sync with your C# domain classes.

πŸ”§ Tip: Never hand‐edit the .Designer.csβ€”always let EF Core regenerate it via migrations.