š Documentation: AddColumnsToPayrollFringe.Designer.cs
File:
IrbyImaging.DbContext/Migrations/20250227124018_AddColumnsToPayrollFringe.Designer.cs
Purpose: Autoāgenerated EF Core migration snapshot that defines the target model after adding new columns to thePayrollFringeentity.
Table of Contents
- Overview & Purpose
- File Structure
- BuildTargetModel Method
- Key Functional Areas
- 4.1. Entity Definitions
- 4.2. New Columns on
PayrollFringe - 4.3. Relationships & Indexes
- Dependencies & Technologies
- How EF Core Uses This Designer File
- Sample Code Snippet
- UML Class Diagram (Mermaid)
- Usage & Migration Workflow
- Conclusion
1. Overview & Purpose
When you scaffold or add a new migration in Entity Framework Core, EF generates two files:
- A .cs file containing the
Up()/Down()methods for schema changes. - A .Designer.cs snapshot of the entire EF Core model as it should look after applying the migration.
AddColumnsToPayrollFringe.Designer.cs represents the postāmigration model, capturing all entities, properties, relationships, and indexesāmost notably the newly added columns on the
PayrollFringetable.
2. File Structure
IrbyImaging.DbContext/
āāā Migrations/
āāā 20250227124018_AddColumnsToPayrollFringe.cs
āāā 20250227124018_AddColumnsToPayrollFringe.Designer.cs ā this file
- Namespace:
IrbyImaging.DbContext.Migrations - Class:
AddColumnsToPayrollFringe : Migration - Core Method:
BuildTargetModel(ModelBuilder modelBuilder)
3. BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// Disable obsolete warnings
#pragma warning disable 612, 618
// Global model annotations
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// SQL Server IDENTITY columns
modelBuilder.UseIdentityColumns();
// ⦠Entity definitions follow ā¦
}
- Purpose:
Defines the complete EF Core model (tables, columns, keys, indexes, relationships). - When Used:
EF Core uses it internally to compute the differences between the snapshot and your currentDbContextshape.
4. Key Functional Areas
4.1 Entity Definitions
Within BuildTargetModel, each entity is configured:
- Property mappings (
.Property<type>("Name")) - Column types (
.HasColumnType("decimal(18,2)")) - Keys & Indexes (
.HasKey("Id"),.HasIndex(...)) - Table names & Schemas (
.ToTable("PayrollFringe","irby"))
Tip: Youāll see dozens of domain classes (AccountBalances, Equipment, Job, etc.). Weāll zoom in on the changes in
PayrollFringe.
4.2 New Columns on PayrollFringe š
This migration adds several fringeābenefit calculation columns. Below is a summary of all properties on PayrollFringe after this migration:
| Property | Type | Description |
|---|---|---|
| Id | Guid | Primary key |
| EmployeeId š | Guid | FK to Employee |
| EmployeeName | string | Display name |
| JobId | int | Job identifier |
| ActualHrsWorkedForWeek | decimal(18,2) | Newly added: total hours worked for the week |
| _401kCredit | decimal(18,2) | Newly added: 401(k) credit value |
| ApprenticeshipCredit | decimal(18,2) | New credit for apprenticeship |
| CashInLieuOfFringeRequired | decimal(18,2) | Cashāinālieu requirement |
| OtherPTOBenefitAnnualValue, ⦠| decimal(18,2) | Several additional āotherā benefit columns newly added |
| AddedBy, AddedDate, ModifiedBy, ModifiedDate | string/DateTime | Audit fields |
| MondayGrossPay ⦠SundayRate | decimal(18,2) | Daily gross pay, hours & rates |
| PayPeriod401KValue | decimal(18,2) | Newly added: 401(k) for the pay period |
| ⦠(many other benefitārelated fields) |
š New Columns:
ActualHrsWorkedForWeek,_401kCredit,ApprenticeshipCredit,CashInLieuOfFringeRequired, plus other Other⦠columns.
4.3 Relationships & Indexes š
b.HasIndex("EmployeeId"); // Create index on EmployeeId
b.HasKey("Id"); // Primary key
b.HasOne("IrbyImaging.DomainClasses.Employee","PayrollEmployee")
.WithMany()
.HasForeignKey("EmployeeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
- FK to Employee: Each
PayrollFringerow references exactly oneEmployee. - Index on
EmployeeId: Optimizes lookups when joining to Employee.
5. Dependencies & Technologies
- .NET Version: EF Core 9.0.0
- ORM: Entity Framework Core
- Database Provider: Microsoft SQL Server
- Namespace Imports:
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6. How EF Core Uses This Designer File
- Recording Model Snapshot: Tracks the full shape of your model after this migration.
- Migrator Comparison: During subsequent migrations, EF compares the last recorded snapshot to your current
DbContextmodel to generate diffs. - Rollbacks & Model Snapshots: Enables consistent downāmigrations and tooling (e.g.,
Script-Migration).
7. Sample Code Snippet
Below is an excerpt from the PayrollFringe entity mapping:
modelBuilder.Entity("IrbyImaging.DomainClasses.PayrollFringe", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<decimal>("ActualHrsWorkedForWeek") // NEW
.HasColumnType("decimal(18,2)");
b.Property<decimal>("_401kCredit") // NEW
.HasColumnType("decimal(18,2)");
b.Property<decimal>("PayPeriod401KValue") // NEW
.HasColumnType("decimal(18,2)");
// ⦠many more properties ā¦
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("PayrollFringe","irby");
});
8. UML Class Diagram (Mermaid)
classDiagram
class Employee {
+Guid EmployeeId
+string DisplayName
+ICollection~PayrollFringe~ PayrollFringes
}
class PayrollFringe {
+Guid Id
+Guid EmployeeId
+decimal ActualHrsWorkedForWeek
+decimal _401kCredit
+decimal ApprenticeshipCredit
+decimal CashInLieuOfFringeRequired
+decimal PayPeriod401KValue
+DateTime AddedDate
+DateTime ModifiedDate
+⦠other columns ā¦
}
Employee "1" <-- "0..*" PayrollFringe : PayrollEmployee
9. Usage & Migration Workflow
- Add Migration:
dotnet ef migrations add AddColumnsToPayrollFringe - Review the Scaffolded Files:
20250227124018_AddColumnsToPayrollFringe.cs20250227124018_AddColumnsToPayrollFringe.Designer.cs
- Apply to Database:
dotnet ef database update - Verification:
- Confirm new columns in SQL Server Management Studio
- Use
DbContext.PayrollFringesin code to read/write the new properties.
10. Conclusion
This Designer file is a critical part of EF Coreās migration infrastructure. It snapshots the entire modelāincluding your newly added fringeābenefit columnsāso that EF Core can:
- Accurately compute future migrations
- Support reliable rollbacks
- Keep your model and database in sync
With the new columns in PayrollFringe, your application can now store and query detailed payroll fringe benefits (401(k), apprenticeship credits, cashāinālieu, etc.) on a perāemployee/week basis. šÆ
Happy coding! š