πŸ“– Documentation: AddPayrollMatchTable (Migration Designer)

Auto-generated EF Core migration designer file for adding, configuring, and mapping the PayrollMatch table in the IrbyContext.
File path:
IrbyImaging.DbContext/Migrations/20250211125043_AddPayrollMatchTable.Designer.cs


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Migration Structure
  3. BuildTargetModel Method
  4. Key Entity: PayrollMatch
  5. Entity Relationships & Indexes
  6. Dependencies & Technologies
  7. Usage Examples
  8. Applying & Reverting the Migration
  9. UML Class Diagram
  10. Conclusion

πŸ” 1. Overview & Purpose

What is this file?
This is the EF Core designer for the AddPayrollMatchTable migration (timestamp 20250211125043). It contains the snapshot of the target database model after this migration is applied.

Why does it exist?

  • EF Core uses this to compare the current model with previous snapshots when creating future migrations.
  • It captures entities, properties, relationships, and schema annotations.
  • Enables precise Up/Down SQL generation without manual scripting.

πŸ—οΈ 2. Migration Structure

namespace IrbyImaging.DbContext.Migrations
{
  [DbContext(typeof(IrbyContext))]
  [Migration("20250211125043_AddPayrollMatchTable")]
  partial class AddPayrollMatchTable
  {
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
      // …Long list of modelBuilder configurations…
    }
  }
}
  • Attributes
    • [DbContext(typeof(IrbyContext))] – associates this migration with the IrbyContext.
    • [Migration("20250211125043_AddPayrollMatchTable")] – timestamped identifier for ordering.
  • Method
    • BuildTargetModel(ModelBuilder modelBuilder) – reconstructs the complete EF Core model as C# code.

βš™οΈ 3. BuildTargetModel Method

  • Purpose: Defines every table, column, key, index, relationship, and annotation in a fluent API style.
  • Key Sections:
    1. Global Annotations
      modelBuilder
        .HasAnnotation("ProductVersion", "9.0.0")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);
      SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
      
    2. Entity Definitions
      Repeats for every domain class under IrbyImaging.DomainClasses.*.
    3. Property Mappings
      .Property<T>("ColumnName") .HasColumnType("sqlType") [...]
    4. Keys & Indexes
      • b.HasKey("Id")
      • b.HasIndex("ForeignKey")
    5. Relationships
      • HasOne(...).WithMany(...).HasForeignKey(...).OnDelete(...)

πŸ’Ό 4. Key Entity: PayrollMatch

This migration introduces (or refreshes) the PayrollMatch entity mapping:

CLR Type Table Schema
IrbyImaging.DomainClasses.PayrollMatch PayrollMatch irby

πŸ“ Columns

Property CLR Type SQL Type Notes
PayrollMatchId Guid uniqueidentifier PK, identity
AddedBy string nvarchar(max)
AddedDate DateTime datetime2
EmployeeId Guid uniqueidentifier FK β†’ Employee
EmployeeMatch decimal decimal(18,2) Employee portion
EmployerMatch decimal decimal(18,2) Employer portion
ModifiedBy string nvarchar(max)
ModifiedDate DateTime datetime2

πŸ”‘ Primary Key & Index

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

πŸ”— 5. Entity Relationships & Indexes

Relationship to Employee

modelBuilder.Entity("IrbyImaging.DomainClasses.PayrollMatch", b =>
{
  b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
   .WithMany()                    // No navigation collection on Employee
   .HasForeignKey("EmployeeId")
   .OnDelete(DeleteBehavior.Cascade)
   .IsRequired();
});
  • Cascade delete: Deleting an Employee automatically removes associated PayrollMatch records.
  • Index: On EmployeeId for fast lookups.

πŸ”Œ 6. Dependencies & Technologies

Technology Version Purpose
.NET / C# 7+ Core application platform
EntityFrameworkCore 9.0.0 ORM & Migrations
SQL Server (Relational) any supported Underlying database engine

πŸ› οΈ 7. Usage Examples

7.1 Creating the Migration

dotnet ef migrations add AddPayrollMatchTable

7.2 Applying to Database

dotnet ef database update

Generated SQL (snippet)

CREATE TABLE [irby].[PayrollMatch] (
    [PayrollMatchId] UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
    [AddedBy] NVARCHAR(MAX) NULL,
    [AddedDate] DATETIME2 NOT NULL,
    [EmployeeId] UNIQUEIDENTIFIER NOT NULL,
    [EmployeeMatch] DECIMAL(18,2) NOT NULL,
    [EmployerMatch] DECIMAL(18,2) NOT NULL,
    [ModifiedBy] NVARCHAR(MAX) NULL,
    [ModifiedDate] DATETIME2 NOT NULL,
    CONSTRAINT [PK_PayrollMatch] PRIMARY KEY ([PayrollMatchId]),
    CONSTRAINT [FK_PayrollMatch_Employee] FOREIGN KEY ([EmployeeId])
       REFERENCES [irby].[Employee]([EmployeeId]) ON DELETE CASCADE
);

CREATE INDEX IX_PayrollMatch_EmployeeId
    ON [irby].[PayrollMatch]([EmployeeId]);

πŸ”„ 8. Applying & Reverting the Migration

  • Apply: dotnet ef database update 20250211125043_AddPayrollMatchTable
  • Revert: dotnet ef database update <PreviousMigrationName>

πŸ“Š 9. UML Class Diagram

classDiagram
  class Employee {
    +Guid EmployeeId
    +string FirstName
    +string LastName
    ...
  }
  class PayrollMatch {
    +Guid PayrollMatchId
    +DateTime AddedDate
    +decimal EmployeeMatch
    +decimal EmployerMatch
    +DateTime ModifiedDate
  }
  Employee "1" <-- "0..*" PayrollMatch : has many
  • Legend
    • Solid arrow:Β PayrollMatch.EmployeeId β†’ Employee.EmployeeId
    • Multiplicities: 1 Employee can have 0–many PayrollMatch records.

🎯 10. Conclusion

  • This designer file is a snapshot of your EF model after adding the PayrollMatch table.
  • It drives EF Core’s ability to generate Up/Down migrations reliably.
  • Key takeaway: Review BuildTargetModel to understand how EF Core perceives your domain schema, constraints, and relationships.

Happy coding! πŸš€