šļø 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
- Overview & Purpose
- EF Core Migration System Primer
- BuildTargetModel Method Explained
- Key Entities & Relationships
- How to Use This Migration
- Dependencies & Technologies
- ThirdāParty Integrations
- Sample Commands & Code Snippets
- 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.csfiles. Instead, update your domain classes and reārundotnet ef migrations add ā¦.
2. EF Core Migration System Primer
- Design Time Model Snapshot (
.Designer.cs) - Migration Files (
Up()/Down()) - 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 ā¦
}
HasAnnotationsets modelāwide metadata (EF version, max identifier length).UseIdentityColumnsinstructs 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Ā
PayrollMatchrecords ā OneĀEmployee(FK onEmployeeId)
2. Employee Entity
Holds core HR data:
- PK:
EmployeeId - Indexes:
- Unique on
JdeNumber
- Unique on
- FKs:
JobIdāJobDepartmentIdāDepartmentRoleIdā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
- Ensure your domain class (
PayrollMatch) has the new property you want to add. - Scaffold the migration:
dotnet ef migrations add AddColumnToPayrollMatchTable - Apply to your database:
dotnet ef database update - 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.csfiles ā 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! š