📑 AddMeterColumnEquipmentEntry.Designer.cs Documentation
Table of Contents
- Overview & Purpose
- EF Core Migrations Primer
- File Structure & Metadata
- Key Functional Area: BuildTargetModel
- Key Change: Adding the Meter Column 🚀
- Model Snapshot Highlights
- Usage & Applying This Migration
- Dependencies & Technologies 🔧
- 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
Meterproperty on theEquipmentEntryentity, enabling tracking of meter readings for equipment usage.
EF Core Migrations Primer
Entity Framework Core migrations consist of three main pieces:
- Migration Class (
AddMeterColumnEquipmentEntry.cs) – defines theUp()/Down()methods (DDL operations). - Designer File (
AddMeterColumnEquipmentEntry.Designer.cs) – holds the model snapshot viaBuildTargetModel(). - 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
EquipmentEntrytable tracked only hours (worked & idle) and odometer.
After: You can now persist aMeterreading (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
- Scaffold (already done):
dotnet ef migrations add AddMeterColumnEquipmentEntry - Apply to Database:
dotnet ef database update - Result:
- The
irby.EquipmentEntrytable now has a FLOAT column namedMeter. - All other schema objects remain in sync with your domain model snapshot.
- The
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
Metercolumn onEquipmentEntry. - 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.