📑 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 the AddWorkDateToEquipmentEntry migration.
Do NOT edit this file manually.


📋 Table of Contents

  1. 🌐 Overview & Purpose
  2. 🔌 Dependencies & Technologies
  3. 🏗️ Code Structure
  4. 🔍 Key Component: EquipmentEntry Entity
  5. ⚙️ BuildTargetModel Method Walkthrough
  6. 🚀 How to Apply This Migration
  7. 💡 Usage Example
  8. 🏁 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/Down methods live in the companion .cs file).
  • Maintain a complete blueprint of all entities and relationships.

Primary Change

  • Added the WorkDate column (of type DateTime) to the EquipmentEntry entity.

🔌 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)
  1. Attributes

    • [DbContext(typeof(IrbyContext))] — associates this migration with the IrbyContext.
    • [Migration("20250310024708_AddWorkDateToEquipmentEntry")] — timestamped identifier.
  2. 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.cs migration 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

  1. Annotations & Conventions

    modelBuilder
      .HasAnnotation("ProductVersion", "9.0.0")
      .HasAnnotation("Relational:MaxIdentifierLength", 128);
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
    
  2. 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.
  3. Relationships

    • EquipmentEntry → EquipmentTimesheet (1:Many)
    • EquipmentTimesheet → Equipment (1:Many)
    • ...
    • Each .HasOne(...).WithMany(...).HasForeignKey(...) is wired up.
  4. Discriminator & Inheritance

    • Assets (e.g., Computer, Monitor) share the same table via TPH (Table‑Per‑Hierarchy).

🛑 We’ve elided other entities for brevity – the complete model includes Customers, Jobs, Employees, FieldTimesheets, etc.


🚀 How to Apply This Migration

  1. Generate the Migration

    dotnet ef migrations add AddWorkDateToEquipmentEntry
    
  2. Inspect the generated files:

    • */AddWorkDateToEquipmentEntry.cs → contains Up()/Down() with SQL for adding/dropping WorkDate.
    • */AddWorkDateToEquipmentEntry.Designer.cs → this blueprint.
  3. 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.