📑 Migration Designer: 20240802133735_AddReferenceNumberToTimesheet.Designer.cs

Location:
IrbyImaging.DbContext/Migrations/20240802133735_AddReferenceNumberToTimesheet.Designer.cs

Note: This file is auto‐generated by Entity Framework Core to capture a snapshot of the model after the AddReferenceNumberToTimesheet migration has been applied.
Do not edit this file by hand; use EF Core tools instead.


🚀 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Model Snapshot
    4.1 Annotations & Conventions
    4.2 Entity Configurations
  5. Focus: MechanicTimesheet Entity
    5.1 New Property: ReferenceNumber
    5.2 Identity & Keys
  6. Relationships & Navigation Properties
  7. Applying the Migration
  8. UML Class Diagram
  9. Conclusion

1. Overview & Purpose

This designer file defines the complete EF Core model after the AddReferenceNumberToTimesheet migration. EF Core uses it to:

  • Reconstruct the database schema at this point in time.
  • Enable comparisons when adding, updating, or rolling back migrations.
  • Ensure consistent schema generation across environments.

Tip: To generate or update migrations, run EF Core CLI commands; never hand‐edit designer files.


2. Dependencies & Technologies

Technology Version
Microsoft.EntityFrameworkCore 7.0.7
Microsoft.EntityFrameworkCore.SqlServer 7.0.7
.NET 7.0
  • DbContext: IrbyContext
  • Database Provider: SQL Server
  • Migrations: EF Core Code‑First

3. Key Functional Areas

  1. BuildTargetModel: Core method that defines every entity, property, key, index, table mapping, and relationship.
  2. Annotations: Global settings (e.g., EF version, identifier length).
  3. Identity & Value Conventions: Enables SQL Server identity columns by default.

4. Model Snapshot

4.1 Annotations & Conventions

At the top of BuildTargetModel, global settings are applied:

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

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
  • ProductVersion: Tracks EF Core version.
  • MaxIdentifierLength: Caps SQL identifiers at 128 characters.
  • UseIdentityColumns: Configures IDENTITY(1,1) on integer keys by default.

4.2 Entity Configurations

Each modelBuilder.Entity(...) call configures an entity. Example excerpt for the Asset entity:

Setting Code Snippet
Table mapping .ToTable("Asset", "irby")
Primary Key .HasKey("Id")
Discriminator .HasDiscriminator<string>("Discriminator").HasValue("Asset")
Properties
b.Property<Guid>("Id")
 .ValueGeneratedOnAdd()
 .HasColumnType("uniqueidentifier");
b.Property<string>("Category")
 .IsRequired()
 .HasColumnType("nvarchar(max)");

5. Focus: MechanicTimesheet Entity

This migration’s main purpose is to introduce a reference number on mechanic timesheets.

5.1 New Property: ReferenceNumber

modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b =>
{
    b.Property<int>("ReferenceNumber")
     .HasColumnType("int");
    // … other properties …
    b.HasKey("Id");
    b.ToTable("MechanicTimesheet", "irby");
});
  • Property: ReferenceNumber
  • Type: int
  • Column: [irby].[MechanicTimesheet].ReferenceNumber

5.2 Identity & Keys

The timesheet still uses a GUID primary key (Id) and an identity column for TimesheetNumber:

b.Property<int>("TimesheetNumber")
 .ValueGeneratedOnAdd()
 .HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("TimesheetNumber"));

6. Relationships & Navigation Properties

Relationships are configured below the entity definitions.
Example: Linking MechanicTimesheet to its Employee:

modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b =>
{
  // … properties …
  b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
   .WithMany()
   .HasForeignKey("EmployeeId")
   .OnDelete(DeleteBehavior.Cascade)
   .IsRequired();

  b.Navigation("Employee");
});

7. Applying the Migration

  1. Add Migration
    dotnet ef migrations add AddReferenceNumberToTimesheet
    
  2. Apply to Database
    dotnet ef database update
    
  3. Verify
    SELECT COLUMN_NAME
      FROM INFORMATION_SCHEMA.COLUMNS
     WHERE TABLE_SCHEMA = 'irby'
       AND TABLE_NAME   = 'MechanicTimesheet';
    -- Should list 'ReferenceNumber'
    

8. UML Class Diagram

classDiagram
    class MechanicTimesheet {
        <<Entity>>
        + Guid Id
        + string Description
        + Guid EmployeeId
        + DateTime StartDate
        + string StartTime
        + string EndTime
        + string RegularTime
        + string OverTime
        + string PayCode
        + string Job
        + string WorkOrder
        + string WorkOrderType
        + int Status
        + string SubmittedBy
        + DateTime SubmittedDate
        + string RejectionComment
        + int TimesheetNumber <<identity>>
        + int ReferenceNumber
    }
    MechanicTimesheet --> Employee : EmployeeId

9. Conclusion

✅ This snapshot ensures EF Core knows about the new ReferenceNumber column on MechanicTimesheet.

  • Pro Tip: Always use EF Core commands to generate migrations.
  • Next Steps: Update your business logic, DTOs, or UI to surface and consume the new ReferenceNumber.

Happy Coding! 🚀