📑 Migration: AddTimesheetNumber (20250303151248)

File: IrbyImaging.DbContext/Migrations/20250303151248_AddTimesheetNumber.Designer.cs
Generated On: 2025-03-03T15:12:48


🗂 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Migration Class Structure
  4. BuildTargetModel Method
  5. Data Model Change: FieldTimesheet
  6. UML Diagram
  7. Usage Example
  8. Conclusion

1. Overview & Purpose

This auto‑generated designer file represents the Entity Framework Core snapshot of your model at the point of the AddTimesheetNumber migration. Its primary role is to:

  • Capture the complete shape of your EF model (all entities, properties, relationships)
  • Reflect the introduction of an identity column TimesheetNumber on the FieldTimesheet table
  • Enable EF Core to compute diffs and apply further migrations correctly

“Migrations snapshots” like this ensure consistency between future code changes and the database schema.


2. Dependencies & Technologies

Technology / Package Version Purpose
Microsoft.EntityFrameworkCore 9.0.0 Core ORM, model building & migrations
Microsoft.EntityFrameworkCore.Relational 9.0.0 Relational database extensions (SQL Server)
Microsoft.EntityFrameworkCore.SqlServer 9.0.0 SQL Server provider
Microsoft.EntityFrameworkCore.Design 9.0.0 Migrations and tooling support

3. Migration Class Structure

[DbContext(typeof(IrbyContext))]
[Migration("20250303151248_AddTimesheetNumber")]
partial class AddTimesheetNumber
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        // ... entity configurations ...
    }
}
  • Attributes

    • [DbContext(typeof(IrbyContext))] ties this snapshot to your custom IrbyContext.
    • [Migration("…")] identifies the unique timestamped migration.
  • Partial Class allows you to extend it (if absolutely needed) without modifying the generated code.


4. BuildTargetModel Method

This method reconstructs the entire EF Core model. Key steps include:

  1. Global Annotations

    modelBuilder
        .HasAnnotation("ProductVersion", "9.0.0")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
    
    • Sets EF Core version & SQL Server max identifier length.
    • Enables Identity columns by default.
  2. Entity Configurations

    • All domain entities (AccountBalances, Job, Employee, FieldTimesheet, etc.) are described here.
    • Each .Entity("…", b => { … }) block configures properties, keys, indexes, relationships, and table mappings.
  3. Relationships & Navigations

    • After properties, the snapshot wires up foreign‑key constraints and .Navigation(...) calls.

5. Data Model Change: FieldTimesheet

The sole substantive change introduced by this migration is the addition of the identity column TimesheetNumber on the FieldTimesheet entity.

Property Type Configuration
TimesheetId Guid Primary key
TimesheetNumber int Identity/auto-increment (ValueGeneratedOnAdd())
modelBuilder.Entity("IrbyImaging.DomainClasses.FieldTimesheet", b =>
{
    b.Property<Guid>("TimesheetId")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");

    // 💡 Newly added identity column
    b.Property<int>("TimesheetNumber")
     .ValueGeneratedOnAdd()
     .HasColumnType("int");
    SqlServerPropertyBuilderExtensions.UseIdentityColumn(
        b.Property<int>("TimesheetNumber")
    );

    // other properties …
    b.HasKey("TimesheetId");
    b.ToTable("FieldTimesheet", "irby");
});
  • Why?
    • Prior to this, timesheets were only uniquely identified by a GUID (TimesheetId).
    • The new TimesheetNumber provides a human‑friendly, sequential integer for reporting/lookup.

6. UML Diagram

@startuml
entity "FieldTimesheet (irby)" {
  * TimesheetId : Guid <<PK>>
  * TimesheetNumber : int <<Identity>>
  --
  ApprovedBy     : string
  ApprovedDate   : DateTime
  CreatedDate    : DateTime
  // … other props …
}
@enduml

Figure: Conceptual shape of the FieldTimesheet table after this migration.


7. Usage Example

  1. Create Migration
    dotnet ef migrations add AddTimesheetNumber
    
  2. Apply to Database
    dotnet ef database update
    
  3. Verify
    SELECT TimesheetNumber, * 
      FROM irby.FieldTimesheet 
     ORDER BY TimesheetNumber DESC;
    

8. Conclusion

👍 This designer snapshot is critical for ensuring your EF Core model remains in sync with your database schema across migrations. The addition of TimesheetNumber as an identity column:

  • Improves readability & reporting
  • Eases integration with legacy systems requiring numeric identifiers
  • Retains GUID PK for internal uniqueness

Next Steps: Review your application code where you insert or read timesheets—to leverage the new TimesheetNumber (e.g., display on UI, include in logs or audit trails).


Generated by EF Core – keep this file under source control, do not manually edit! 🚀