📑 AddWorkDateToEquipmentEntry.Designer.cs Documentation
Location:
IrbyImaging.DbContext/Migrations/20250310024708_AddWorkDateToEquipmentEntry.Designer.cs
Auto‑Generated by: Entity Framework Core Migrations
Purpose: Defines the target database model after applying theAddWorkDateToEquipmentEntrymigration.
Do NOT edit this file manually.
📋 Table of Contents
- 🌐 Overview & Purpose
- 🔌 Dependencies & Technologies
- 🏗️ Code Structure
- 🔍 Key Component: EquipmentEntry Entity
- ⚙️ BuildTargetModel Method Walkthrough
- 🚀 How to Apply This Migration
- 💡 Usage Example
- 🏁 Conclusion
🌐 Overview & Purpose
This Designer file is part of the EF Core Migration AddWorkDateToEquipmentEntry. Its sole responsibility is to describe the target shape of the data model after the migration is applied, enabling EF Core to:
- Compare the current model to the snapshot and generate SQL.
- Scaffold database operations (
Up/Downmethods live in the companion.csfile). - Maintain a complete blueprint of all entities and relationships.
Primary Change
- Added the
WorkDatecolumn (of typeDateTime) to theEquipmentEntryentity.
🔌 Dependencies & Technologies
| Technology | Version/Feature |
|---|---|
| .NET / C# | .NET 7.0+ |
| Entity Framework Core | 9.0.0 |
| SQL Server (Relational) | UseIdentityColumns strategy |
| Nullable Reference Types | Disabled (#nullable disable) |
🏗️ Code Structure
AddWorkDateToEquipmentEntry.Designer.cs
└───namespace IrbyImaging.DbContext.Migrations
└───partial class AddWorkDateToEquipmentEntry
└───protected override void BuildTargetModel(ModelBuilder modelBuilder)
-
Attributes
[DbContext(typeof(IrbyContext))]— associates this migration with theIrbyContext.[Migration("20250310024708_AddWorkDateToEquipmentEntry")]— timestamped identifier.
-
BuildTargetModel
- Invoked by EF Core tooling to build the complete model metadata.
- Contains
.Entity(...)calls for every mapped class.
🔔 Note: This file only defines the model. The actual SQL operations (adding/dropping the column) live in the corresponding
AddWorkDateToEquipmentEntry.csmigration file.
🔍 Key Component: EquipmentEntry Entity
The star of this migration is the EquipmentEntry entity. We’ve injected a new property:
modelBuilder.Entity("IrbyImaging.DomainClasses.EquipmentEntry", b =>
{
b.Property<Guid>("EquipmentEntryId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// ⏰ Existing columns ...
b.Property<string>("CostCode").HasColumnType("nvarchar(max)");
b.Property<Guid>("EquipmentTimesheetId").HasColumnType("uniqueidentifier");
b.Property<double>("IdleHours").HasColumnType("float");
b.Property<string>("JobNo").HasColumnType("nvarchar(max)");
b.Property<double>("OdometerReading").HasColumnType("float");
b.Property<double>("WorkedHours").HasColumnType("float");
// 🔥 Newly added WorkDate column
b.Property<DateTime>("WorkDate")
.HasColumnType("datetime2");
b.HasKey("EquipmentEntryId");
b.HasIndex("EquipmentTimesheetId");
b.ToTable("EquipmentEntry", "irby");
});
| Column Name | Type | Description |
|---|---|---|
| WorkDate | datetime2 |
Date the equipment was used. |
⚙️ BuildTargetModel Method Walkthrough
-
Annotations & Conventions
modelBuilder .HasAnnotation("ProductVersion", "9.0.0") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); -
Entity Definitions
- ~200 calls to
modelBuilder.Entity(...)describing tables, columns, keys, indexes, relationships. - Fluent API configures column types, identity columns, discriminators (TPH inheritance), and navigation properties.
- ~200 calls to
-
Relationships
EquipmentEntry→EquipmentTimesheet(1:Many)EquipmentTimesheet→Equipment(1:Many)- ...
- Each
.HasOne(...).WithMany(...).HasForeignKey(...)is wired up.
-
Discriminator & Inheritance
- Assets (e.g.,
Computer,Monitor) share the same table via TPH (Table‑Per‑Hierarchy).
- Assets (e.g.,
🛑 We’ve elided other entities for brevity – the complete model includes Customers, Jobs, Employees, FieldTimesheets, etc.
🚀 How to Apply This Migration
-
Generate the Migration
dotnet ef migrations add AddWorkDateToEquipmentEntry -
Inspect the generated files:
*/AddWorkDateToEquipmentEntry.cs→ containsUp()/Down()with SQL for adding/droppingWorkDate.*/AddWorkDateToEquipmentEntry.Designer.cs→ this blueprint.
-
Update the Database
dotnet ef database update
💡 Usage Example
After applying the migration, you can read/write WorkDate:
using var context = new IrbyContext();
// Create a new entry
var entry = new EquipmentEntry {
EquipmentTimesheetId = ts.Id,
CostCode = "CC100",
IdleHours = 0.5,
WorkedHours = 7.5,
OdometerReading = 1234.5,
JobNo = "J-2025-01",
WorkDate = DateTime.UtcNow // ← new property!
};
context.Add(entry);
context.SaveChanges();
// Query by date
var todayEntries = context.EquipmentEntries
.Where(e => e.WorkDate.Date == DateTime.Today)
.ToList();
🏁 Conclusion
This Designer file is critical for EF Core’s internal snapshotting of your model after adding the new WorkDate field to the EquipmentEntry table.
- ✅ Auto‑generated – do not modify by hand.
- ✅ Describes the shape of your entire domain.
- ✅ Enables smooth database updates using
dotnet ef database update.
Keep your migrations sharp, granular, and well‑documented! 🚀
Generated with ❤️ and EF Core Migrations best practices.