📑 AddMeterColumnEquipmentEntry.Designer.cs Documentation


Table of Contents

  1. Overview & Purpose
  2. EF Core Migrations Primer
  3. File Structure & Metadata
  4. Key Functional Area: BuildTargetModel
  5. Key Change: Adding the Meter Column 🚀
  6. Model Snapshot Highlights
  7. Usage & Applying This Migration
  8. Dependencies & Technologies 🔧
  9. Conclusion 🏁

Overview & Purpose

This auto-generated Designer file is part of an Entity Framework Core migration named 20250313205835_AddMeterColumnEquipmentEntry. Its sole responsibility is to define a snapshot of your entire domain model after applying the corresponding migration operations.

  • 🔍 Why? EF Core uses this snapshot to compare your current model against previous migrations and to generate diffs for future migrations.
  • 📌 Focus: This snapshot now includes a brand-new Meter property on the EquipmentEntry entity, enabling tracking of meter readings for equipment usage.

EF Core Migrations Primer

Entity Framework Core migrations consist of three main pieces:

  1. Migration Class (AddMeterColumnEquipmentEntry.cs) – defines the Up()/Down() methods (DDL operations).
  2. Designer File (AddMeterColumnEquipmentEntry.Designer.cs) – holds the model snapshot via BuildTargetModel().
  3. Model Snapshot – EF’s understanding of your DbContext’s shape at a point in time.

This Designer file is not edited by hand; it’s regenerated each time you scaffold a migration.


File Structure & Metadata

IrbyImaging.DbContext/
  └── Migrations/
       ├── 20250313205835_AddMeterColumnEquipmentEntry.cs
       └── 20250313205835_AddMeterColumnEquipmentEntry.Designer.cs ← This file
Attribute Description
[DbContext(typeof(IrbyContext))] Binds this migration to the IrbyContext.
[Migration("20250313205835_AddMeterColumnEquipmentEntry")] Unique migration identifier (timestamp + name).

Key Functional Area: BuildTargetModel

The heart of the Designer file is the override:

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    // Disables obsolete warnings
    #pragma warning disable 612, 618

    modelBuilder
      .HasAnnotation("ProductVersion", "9.0.0")
      .HasAnnotation("Relational:MaxIdentifierLength", 128);

    // Use SQL Server identity columns by default
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // ⬇ Entity configurations follow
    modelBuilder.Entity("IrbyImaging.DomainClasses.EquipmentEntry", b =>
    {
        b.Property<Guid>("EquipmentEntryId")
            .ValueGeneratedOnAdd()
            .HasColumnType("uniqueidentifier");

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

        // NEW PROPERTY: Meter
        b.Property<double>("Meter")
            .HasColumnType("float");

        b.Property<double>("OdometerReading")
            .HasColumnType("float");

        b.Property<DateTime>("WorkDate")
            .HasColumnType("datetime2");

        b.Property<double>("WorkedHours")
            .HasColumnType("float");

        b.HasKey("EquipmentEntryId");
        b.HasIndex("EquipmentTimesheetId");
        b.ToTable("EquipmentEntry", "irby");
    });

    // ... configurations for all other entities
    #pragma warning restore 612, 618
}
  • ModelBuilder: Fluent API for configuring entities, properties, keys, relationships, table names, and schema.
  • Each modelBuilder.Entity(...) block describes one table.

Key Change: Adding the Meter Column 🚀

This migration introduces a brand-new column in the EquipmentEntry table:

Entity Column Name Data Type Description
EquipmentEntry Meter float New field to record meter readings

Before: The EquipmentEntry table tracked only hours (worked & idle) and odometer.
After: You can now persist a Meter reading (e.g., engine hours, service intervals).


Model Snapshot Highlights

While the Designer file enumerates 200+ entities, here is a UML‑style overview of the Equipment sub‑model that’s impacted:

+---------------------+       +-------------------------+
|   Equipment         |1     *| EquipmentTimesheet     |
|---------------------|-------|------------------------|
| EquipmentId : GUID  |       | EquipmentTimesheetId   |
| Name            ... |       | TimesheetId   : GUID   |
+---------------------+       +-----------+-----------+
                                          |
                                          |1
                                          * 
                                +---------------------+
                                |  EquipmentEntry     |
                                |---------------------|
                                | EquipmentEntryId:GUID 
                                | WorkDate       :DateTime
                                | WorkedHours    :double
                                | Meter          :double  ← **New**
                                +---------------------+
  • Relations:
    • EquipmentEntry ➞ EquipmentTimesheet (many-to-one)
    • EquipmentTimesheet ➞ Equipment (many-to-one)

Usage & Applying This Migration

  1. Scaffold (already done):
    dotnet ef migrations add AddMeterColumnEquipmentEntry
    
  2. Apply to Database:
    dotnet ef database update
    
  3. Result:
    • The irby.EquipmentEntry table now has a FLOAT column named Meter.
    • All other schema objects remain in sync with your domain model snapshot.

Dependencies & Technologies 🔧

Technology Version
.NET 9.0.0
Microsoft.EntityFrameworkCore 9.0.0
Microsoft.EntityFrameworkCore.SqlServer 9.0.0
C# 10.0+

No third‑party libraries beyond EF Core are involved in this Designer file.


Conclusion 🏁

  • What? A snapshot of your EF Core model including the new Meter column on EquipmentEntry.
  • Why? EF Core uses this to detect schema changes and drive future migrations.
  • How? You normally don’t edit designer files by hand—they regenerate when you scaffold migrations.

By adding the Meter property and updating the model snapshot here, your application can now store meter readings alongside hours and odometer values, improving equipment usage reporting and maintenance schedules.