📚 Migration Documentation

File: IrbyImaging.DbContext/Migrations/20240724182925_AddAutoIncrementTimesheetNumber.Designer.cs
Namespace: IrbyImaging.DbContext.Migrations
Generated: EF Core 7.0.7 for SQL Server


📋 Table of Contents

  1. ✨ Overview & Purpose
  2. ⚙️ Dependencies & Technologies
  3. 🏗️ Key Functional Areas
  4. 🔍 Migration Details
  5. 🗄️ Domain Entities Summary
  6. 🖼️ Simplified UML Class Diagram
  7. 🚀 Usage & Applying Migration
  8. 🧪 Testing & Verification
  9. 📘 Further Reading & References

✨ Overview & Purpose

This auto‑generated designer file captures the target database model after applying the migration 20240724182925_AddAutoIncrementTimesheetNumber. Its primary goal is to:

  • Reflect a new Identity / Auto‑Increment setting for the TimesheetNumber column on the MechanicTimesheet table.
  • Maintain a snapshot of all domain entities, relationships, indexes, and SQL Server conventions in use.

Why Designer.cs?
EF Core splits a migration into two files:

  1. Up/Down logic (shows DDL changes)
  2. Designer (this one)—captures the entire model structure as of this migration.

⚙️ Dependencies & Technologies

Technology Version Purpose
.NET 7.0 Runtime framework
Entity Framework Core 7.0.7 ORM & migration engine
SQL Server ≥2016 Relational database provider
C# / Visual Studio C# 11 / VS 2022 Development environment

🏗️ Key Functional Areas

  • Model Snapshot
    • Declares all entities, properties, keys, indexes, and relationships.
  • Identity Columns
    • Applies UseIdentityColumns() at model level (SQL Server identity).
  • Entity‑Inheritance (TPH)
    • Assets and its derived classes (Computer, MobileDevice, etc.) share a single table with discriminator.
  • New Auto‑Increment
    • Adds identity configuration to MechanicTimesheet.TimesheetNumber.

🔍 Migration Details

4.1 BuildTargetModel Method

The heart of the designer file is:

protected override void BuildTargetModel(ModelBuilder modelBuilder) {
    #pragma warning disable 612, 618
    modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    // Globally enable SQL Server identity columns
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // …entity configurations…
    
    #pragma warning restore 612, 618
}
  • HasAnnotation: Records EF Core version and identifier limits.
  • UseIdentityColumns: Switches ValueGeneratedOnAdd() properties to SQL Server IDENTITY columns by default.

4.2 Identity Columns Convention

By calling

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

all integer properties marked with .ValueGeneratedOnAdd() will use IDENTITY(1,1) instead of the legacy Sequence behavior.


4.3 TimesheetNumber Auto-increment

Change introduced by this migration 🎯:

modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b => {
    // … other properties …

    b.Property<int>("TimesheetNumber")
        .ValueGeneratedOnAdd()          // EF Core: generate on INSERT
        .HasColumnType("int");
    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("TimesheetNumber"));
    
    b.HasKey("Id");
    b.ToTable("MechanicTimesheet", "irby");
});
  • Before: TimesheetNumber was a regular integer column.
  • After: It becomes an IDENTITY column (auto‑incremented).

🗄️ Domain Entities Summary

Over 120+ entities are scaffolded. Below is a short sample; full list is in the file.

Entity Name Table Schema.Table Key(s) Important Notes
Asset irby.Asset Id (GUID) TPH base for various asset types (Computer, Monitor, …)
MechanicTimesheet irby.MechanicTimesheet Id (GUID) New identity on TimesheetNumber
Employee irby.Employee EmployeeId (GUID) Unique index on JdeNumber
Job irby.Job JobId (GUID) Unique index on JdeNumber
FieldOffice irby.FieldOffice Id (GUID) Unique index on JdeNumber
TimeSheetEntry irby.TimeSheetEntry TimeSheetEntryId (GUID) FK → Employee, → TimeEntryType
DocumentImage irby.DocumentImage DocumentImageId (GUID) Multi-role booleans, OCR support
Permissions irby.Permissions PermissionId (GUID) Audit trail via LinkRolePermission
… and many more…

🖼️ Simplified UML Class Diagram

classDiagram
    class MechanicTimesheet {
      +Guid Id
      +String CostType
      +DateTime StartDate
      +int TimesheetNumber <<identity>>
    }

    class Asset {
      +Guid Id
      +string SerialNumber
      +string Status
    }
    class Computer
    class MobileDevice

    Asset <|-- Computer
    Asset <|-- MobileDevice

    MechanicTimesheet ..|> Employee : FK_Employee
    Asset --> AssetModel : FK_ModelId
    AssetModel --> Manufacturer
    TimeSheetEntry --> Employee
    TimeSheetEntry --> TimeEntryType

Legend:

  • <<identity>> = Auto‑increment column
  • Solid arrows = inheritance
  • Dashed arrows = relationships

🚀 Usage & Applying Migration

  1. Add migration (already created):
    dotnet ef migrations add AddAutoIncrementTimesheetNumber
    
  2. Update database:
    dotnet ef database update
    
  3. SQL Impact:
    ALTER TABLE [irby].[MechanicTimesheet]
    ADD [TimesheetNumber] int IDENTITY(1,1) NOT NULL;
    
  4. Rolling back:
    dotnet ef database update <previous_migration_name>
    

🧪 Testing & Verification

  • Smoke test: Insert new MechanicTimesheet without specifying TimesheetNumber, then confirm:
    var timesheet = new MechanicTimesheet { /* other properties */ };
    context.MechanicTimesheets.Add(timesheet);
    await context.SaveChangesAsync();
    Console.WriteLine(timesheet.TimesheetNumber); // should be > 0
    
  • Schema diff:
    dotnet ef migrations script --idempotent
    
  • Integration: Confirm EF queries on TimesheetNumber work as expected (e.g. ORDER BY).

📘 Further Reading & References


👍 Congratulations! You now have a detailed map of 20240724182925_AddAutoIncrementTimesheetNumber.Designer.cs. Use this as a reference for understanding your database schema evolution and ensuring consistency across environments.