πŸ—‚οΈ Table of Contents

  1. Introduction
  2. Migration Overview & Purpose
  3. Key Functional Areas
  4. BuildTargetModel Method
  5. Data Models & Entity Mappings
  6. Relationships & UML Diagram
  7. Dependencies & Technologies
  8. Usage Example
  9. Conclusion

Introduction

Welcome to the FieldLogTimesheet migration designer documentation! πŸŽ‰ This file, FieldLogTimesheet.Designer.cs, is an auto-generated snapshot of your Entity Framework Core model at the time of the 20250115153413_FieldLogTimesheet migration. It is part of the IrbyImaging.DbContext.Migrations namespace and captures the state of all your domain entities and their mappings to the SQL Server database.


Migration Overview & Purpose

Migration Name: 20250115153413_FieldLogTimesheet
Designer File: FieldLogTimesheet.Designer.cs
DbContext: IrbyContext

This designer file is not where you define Up/Down operations. Instead, its purpose is to provide EF Core with a model snapshot so that future migrations can compute differences. It ensures consistency and helps EF track schema changes over time.


Key Functional Areas

  • πŸ—οΈ Model Snapshot
    Captures the complete EF Core model at this migration.

  • πŸ”¨ Entity Configurations
    Defines entity properties, column types, primary keys, indexes, and discriminator mappings for table-per-hierarchy (TPH).

  • πŸ”— Relationships
    Configures foreign key relationships and navigation properties.

  • βš™οΈ SQL Server Extensions
    Applies identity column conventions and relational annotations.


BuildTargetModel Method

[DbContext(typeof(IrbyContext))]
[Migration("20250115153413_FieldLogTimesheet")]
partial class FieldLogTimesheet
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        // Suppress obsolete warnings
        #pragma warning disable 612, 618

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

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

        // ... Entity definitions follow ...
        
        #pragma warning restore 612, 618
    }
}
  • Annotations
    • ProductVersion: EF Core version (7.0.7).
    • Relational:MaxIdentifierLength: Max length for SQL identifiers (128).
  • UseIdentityColumns
    Enables default identity (auto-increment) for integer PKs.

Data Models & Entity Mappings

The designer file defines 100+ domain entities. Below we focus on the FieldTimesheet feature and its closely related tables.

Entity Table Schema Description
FieldTimesheet irby.FieldTimesheet Captures a daily field crew sheet.
EmployeeTimesheet irby.EmployeeTimesheet Links employees to a field timesheet.
EquipmentTimesheet irby.EquipmentTimesheet Links equipment to a field timesheet.
WorkEntry irby.WorkEntry Records per-employee work details.
EquipmentEntry irby.EquipmentEntry Records per-equipment usage details.

5.2 Sample Entity: FieldTimesheet

modelBuilder.Entity("IrbyImaging.DomainClasses.FieldTimesheet", b =>
{
    b.Property<Guid>("TimesheetId")
        .ValueGeneratedOnAdd()
        .HasColumnType("uniqueidentifier");
    b.Property<DateTime>("CreatedDate")
        .HasColumnType("datetime2");
    b.Property<string>("CrewId")
        .IsRequired()
        .HasColumnType("nvarchar(max)");
    b.Property<string>("ForemanSignature")
        .HasColumnType("nvarchar(max)");
    b.HasKey("TimesheetId");
    b.ToTable("FieldTimesheet", "irby");
});
  • Primary Key: TimesheetId (GUID)
  • Columns:
    • CreatedDate: Timestamp when sheet was created.
    • CrewId: Identifier for the crew (required).
    • ForemanSignature: Signature or initials.

5.3 Sample Entity: WorkEntry

modelBuilder.Entity("IrbyImaging.DomainClasses.WorkEntry", b =>
{
    b.Property<Guid>("WorkEntryId")
        .ValueGeneratedOnAdd()
        .HasColumnType("uniqueidentifier");
    b.Property<Guid>("EmployeeTimesheetId")
        .HasColumnType("uniqueidentifier");
    b.Property<DateTime>("WorkDate")
        .HasColumnType("datetime2");
    b.Property<double>("RegularHours")
        .HasColumnType("float");
    b.Property<double>("OvertimeHours")
        .HasColumnType("float");
    b.Property<bool>("Lunch")
        .HasColumnType("bit");
    // ... other per diem flags ...
    b.HasIndex("EmployeeTimesheetId");
    b.HasKey("WorkEntryId");
    b.ToTable("WorkEntry", "irby");
});
  • Foreign Key: EmployeeTimesheetId β†’ EmployeeTimesheet.EmployeeTimesheetId
  • Business Data:
    • Hours, meals, per diem, cost codes, etc.

Relationships & UML Diagram

Below is a simplified Entity-Relationship (ER) diagram for the Timesheet domain:

+-----------------+          1      *     +-----------------------+
| FieldTimesheet  |---------------------->| EmployeeTimesheet     |
|-----------------|                       +-----------------------+
| * TimesheetId   |                       | * EmployeeTimesheetId |
|   CreatedDate   |                       |   EmployeeId          |
|   CrewId        |                       |   TimesheetId         |
+-----------------+                       +-------------+---------+
                                               1      * 
                                               +-------------+
                                               |
                                               v
                                       +-----------------+
                                       |    WorkEntry    |
                                       +-----------------+
                                       | * WorkEntryId   |
                                       |   WorkDate      |
                                       |   RegularHours  |
                                       +-----------------+

+-----------------+          1      *     +--------------------------+
| FieldTimesheet  |---------------------->| EquipmentTimesheet       |
+-----------------+                       +--------------------------+
                                               1      *
                                               +-------------+
                                               |
                                               v
                                       +----------------------+
                                       |   EquipmentEntry     |
                                       +----------------------+
                                       | * EquipmentEntryId   |
                                       |   WorkedHours        |
                                       +----------------------+

Dependencies & Technologies

  • .NET 7.0 🎯
  • Entity Framework Core 7.0.7
  • Microsoft.EntityFrameworkCore.SqlServer
  • C# 11
  • SQL Server (identity columns)

No third‑party integrations or external APIs are directly referenced in this designer file.


Usage Example

Generating & Applying the Migration

  1. Add Migration
    dotnet ef migrations add FieldLogTimesheet \
        --context IrbyContext \
        --output-dir Migrations
    
  2. Update Database
    dotnet ef database update --context IrbyContext
    
  3. Inspect Changes
    • The designer snapshot (*.Designer.cs) ensures EF Core knows the current model.
    • The migration file (*.cs) in the same folder contains the Up() and Down() methods.

Querying Field Timesheets

using var ctx = new IrbyContext();
var todaySheets = ctx.FieldTimesheets
    .Include(ft => ft.EmployeeTimesheets)
        .ThenInclude(et => et.WorkEntries)
    .Where(ft => ft.CreatedDate.Date == DateTime.Today)
    .ToList();

Conclusion

The FieldLogTimesheet.Designer.cs file is a comprehensive model snapshot that EF Core uses internally to manage and compare schema changes. It:

  • πŸ“ Defines all domain entities and their column mappings.
  • πŸ”— Configures foreign keys, indexes, and discriminator strategies.
  • βš™οΈ Applies SQL Server conventions for identity columns.

By understanding this file, you gain insight into how your Irb yImaging domain model translates into a relational schema and how EF Core tracks migrations over time. Happy coding! πŸš€