šŸ—ļø Migration: AddColumnToPayrollMatchTable

File: IrbyImaging.DbContext/Migrations/20250211130437_AddColumnToPayrollMatchTable.Designer.cs

āš™ļø Auto‐generated by EF Core 9.0.0 – Do not manually edit


šŸ“‘ Table of Contents

  1. Overview & Purpose
  2. EF Core Migration System Primer
  3. BuildTargetModel Method Explained
  4. Key Entities & Relationships
  5. How to Use This Migration
  6. Dependencies & Technologies
  7. Third‑Party Integrations
  8. Sample Commands & Code Snippets
  9. Conclusion & Best Practices

1. Overview & Purpose

This Designer file is an EF Core model snapshot reflecting the database schema after applying the 20250211130437_AddColumnToPayrollMatchTable migration. It is auto‐generated by the Entity Framework Core tools so that EF Core can:

  • Compare your current model against the snapshot
  • Generate SQL in the Up() / Down() methods of your migration
  • Keep track of all entity types, their properties, indexes, keys, and relationships

Tip: Never manually modify .Designer.cs files. Instead, update your domain classes and re‐run dotnet ef migrations add ….


2. EF Core Migration System Primer

  1. Design Time Model Snapshot (.Designer.cs)
  2. Migration Files (Up() / Down())
  3. Database Update (applies pending migrations)
# 1. Scaffold a new migration after changing your domain model
dotnet ef migrations add AddColumnToPayrollMatchTable

# 2. Apply pending migrations to the target database
dotnet ef database update

3. BuildTargetModel Method Explained

At the heart of this file is the BuildTargetModel(ModelBuilder modelBuilder) method. EF Core uses it to rebuild the entire model in memory:

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    // Global annotations
    modelBuilder
        .HasAnnotation("ProductVersion", "9.0.0")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // Example: Configure PayrollMatch entity
    modelBuilder.Entity("IrbyImaging.DomainClasses.PayrollMatch", b =>
    {
        b.Property<Guid>("PayrollMatchId")
         .ValueGeneratedOnAdd()
         .HasColumnType("uniqueidentifier");

        b.Property<string>("AddedBy")
         .HasColumnType("nvarchar(max)");

        b.Property<DateTime>("AddedDate")
         .HasColumnType("datetime2");

        b.Property<Guid>("EmployeeId")
         .HasColumnType("uniqueidentifier");

        b.Property<decimal>("EmployeeMatch")
         .HasColumnType("decimal(18,2)");

        // ... other properties ...

        b.HasKey("PayrollMatchId");
        b.HasIndex("EmployeeId");
        b.ToTable("PayrollMatch", "irby");
    });

    // … Configuration for dozens of other entities …
}
  • HasAnnotation sets model‐wide metadata (EF version, max identifier length).
  • UseIdentityColumns instructs SQLĀ Server to use IDENTITY(1,1) for key generation.
  • Entity(...) blocks define tables, columns, keys, indexes, and relationships.

4. Key Entities & Relationships

1. PayrollMatch Entity

The purpose of this migration is to add (or modify) a column in the PayrollMatch table. Below is a summary of its configuration:

Column Name Type Description
PayrollMatchId uniqueidentifier PK Primary key, auto‐generated
AddedBy nvarchar(max) Who created the record
AddedDate datetime2 When it was created
EmployeeId uniqueidentifier FK Relation → Employee.EmployeeId
EmployeeMatch decimal(18,2) Fringe matched by the employee
EmployeeNumber nvarchar(max) Internal or JDE number
EmployerMatch decimal(18,2) Fringe matched by the employer
ModifiedBy nvarchar(max) Who last modified
ModifiedDate datetime2 When it was last modified

Relationship

  • ManyĀ PayrollMatch records → OneĀ Employee (FK on EmployeeId)

2. Employee Entity

Holds core HR data:

  • PK: EmployeeId
  • Indexes:
    • Unique on JdeNumber
  • FKs:
    • JobId → Job
    • DepartmentId → Department
    • RoleId → Role

3. Asset Hierarchy (TPH Inheritance)

The Asset base class uses Table‑per‑Hierarchy with a Discriminator column.
Derived types include:

Discriminator Derived Class Additional Properties
Asset Asset Category, SerialNumber, PurchaseDate, Status
Computer Computer AssetNumber, CpsNumber, OperatingSystemId, UnitNumber
MobileDevice MobileDevice Carrier, Imei, IsTelogis, PhoneNumber, Sim, Type
DeskPhone DeskPhone MacAddress, PhoneNumber
... others see code for full list

5. How to Use This Migration

  1. Ensure your domain class (PayrollMatch) has the new property you want to add.
  2. Scaffold the migration:
    dotnet ef migrations add AddColumnToPayrollMatchTable
    
  3. Apply to your database:
    dotnet ef database update
    
  4. Verify the new column exists in irby.PayrollMatch.

šŸ” EF Core will compare your domain classes against the snapshot in this file to generate the correct SQL in Up()/Down().


6. Dependencies & Technologies

  • .NET 7.0+ / .NET 8.0 (C# 11)
  • EF Core 9.0.0
  • Microsoft.EntityFrameworkCore.SqlServer
  • (Optionally) AutoMapper, Swashbuckle for API docs, xUnit/NUnit for tests

7. Third‑Party Integrations

  • EF Core Tools (Microsoft.EntityFrameworkCore.Design)
  • SQLĀ Server (identity columns)
  • Azure DevOps / GitHub Actions for CI/CD migrations

8. Sample Commands & Code Snippets

# List existing migrations
dotnet ef migrations list

# Rolling back to the previous migration
dotnet ef database update <PreviousMigrationName>

# Inspect the SQL script
dotnet ef migrations script 20250211130437_AddColumnToPayrollMatchTable

Example: Add a New Column in Your Domain Class

public class PayrollMatch
{
    public Guid PayrollMatchId { get; set; }
    public decimal EmployeeMatch { get; set; }
    public decimal EmployerMatch { get; set; }

    // NEW property to add
    public string DepartmentCode { get; set; }
}
dotnet ef migrations add AddDepartmentCodeToPayrollMatch
dotnet ef database update

9. Conclusion & Best Practices

  • Never hand‑edit .Designer.cs files – they are auto‑generated snapshots.
  • Always update your domain classes first, then scaffold a migration.
  • Keep migrations small and focused.
  • Use source control to track your migrations folder alongside your code.

šŸŽ‰ With EF Core migrations and this Designer file in place, your database schema evolves safely alongside your application!
Happy coding and smooth schema migrations! šŸš€