📋 Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- Migration Structure
- New PayrollFringe Table
- How It Works
- Usage & Examples
- Conclusion
📝 Overview & Purpose
The AddFringeTable migration designer file (20241202161634_AddFringeTable.Designer.cs) is an auto-generated Entity Framework Core snapshot. It captures the complete state of your EF Core model at the time this migration was created.
- Why it exists:
- Serves as a blueprint for EF Core to understand how to transition your database schema from the previous state to this new state.
- Ensures that the
PayrollFringetable (and any other model changes) are correctly scaffolded and can be applied or rolled back.
🛠️ Key Functional Areas
| Area | Description |
|---|---|
| Model Builder Annotations | Captures EF Core annotations like product version, identifier limits. |
| Entity Registrations | Defines every table (domain class) and its schema in the database. |
| Relationships & FKs | Links entities via foreign keys, cascade rules, navigations. |
| New Table Addition | Introduces PayrollFringe table with columns & indexes. |
🔧 Dependencies & Technologies
- .NET 7.0
- Entity Framework Core 7.0.7
- Microsoft.EntityFrameworkCore.SqlServer
- IrbyImaging.DomainClasses (your domain model assembly)
- IrbyContext (your
DbContextimplementation)
🚧 Migration Structure
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace IrbyImaging.DbContext.Migrations
{
[DbContext(typeof(IrbyContext))]
[Migration("20241202161634_AddFringeTable")]
partial class AddFringeTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// 1. Global annotations
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// 2. Entity definitions (hundreds!)
modelBuilder.Entity("IrbyImaging.DomainClasses.AccountBalances", b => { /* ... */ });
// ...
modelBuilder.Entity("IrbyImaging.DomainClasses.PayrollFringe", b => { /* New table! */ });
// ...
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b => { /* ... */ });
// 3. Relationships & navigations
modelBuilder.Entity("IrbyImaging.DomainClasses.PayrollFringe", b =>
{
b.HasOne("IrbyImaging.DomainClasses.Employee", "PayrollEmployee")
.WithMany()
.HasForeignKey("EmployeeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PayrollEmployee");
});
// ...
}
}
}
➕ New PayrollFringe Table
Entity Definition
This migration introduces the PayrollFringe table under the irby schema:
modelBuilder.Entity("IrbyImaging.DomainClasses.PayrollFringe", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("AddedBy")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("AddedDate")
.HasColumnType("datetime2");
// Fringe cost columns
b.Property<decimal>("CashFringe").HasColumnType("decimal(18,2)");
b.Property<decimal>("CashPayableFringe").HasColumnType("decimal(18,2)");
b.Property<decimal>("Dental").HasColumnType("decimal(18,2)");
b.Property<decimal>("Disability").HasColumnType("decimal(18,2)");
b.Property<decimal>("EAP").HasColumnType("decimal(18,2)");
b.Property<decimal>("FringeHours").HasColumnType("decimal(18,2)");
b.Property<decimal>("FringeRequirement").HasColumnType("decimal(18,2)");
b.Property<decimal>("Health").HasColumnType("decimal(18,2)");
b.Property<decimal>("Holiday").HasColumnType("decimal(18,2)");
b.Property<decimal>("HourlyRate").HasColumnType("decimal(18,2)");
b.Property<decimal>("HoursWorked").HasColumnType("decimal(18,2)");
b.Property<string>("LaborClass").HasColumnType("nvarchar(max)");
b.Property<decimal>("Life").HasColumnType("decimal(18,2)");
b.Property<string>("ModifiedBy").HasColumnType("nvarchar(max)");
b.Property<DateTime>("ModifiedDate").HasColumnType("datetime2");
b.Property<decimal>("RetirmentMatch").HasColumnType("decimal(18,2)");
b.Property<decimal>("Sick").HasColumnType("decimal(18,2)");
b.Property<decimal>("TotalFringe").HasColumnType("decimal(18,2)");
b.Property<decimal>("TrainingFringe").HasColumnType("decimal(18,2)");
b.Property<decimal>("Vacation").HasColumnType("decimal(18,2)");
b.Property<decimal>("Vision").HasColumnType("decimal(18,2)");
b.Property<decimal>("WeeklyFringe").HasColumnType("decimal(18,2)");
b.Property<decimal>("YearlyFringe").HasColumnType("decimal(18,2)");
b.Property<Guid>("EmployeeId").HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("PayrollFringe", "irby");
});
Relationships & Indexes
// Establish a required foreign‐key to Employee
b.HasOne("IrbyImaging.DomainClasses.Employee", "PayrollEmployee")
.WithMany()
.HasForeignKey("EmployeeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
// Navigation property setup
b.Navigation("PayrollEmployee");
- Index on
EmployeeIdspeeds up queries filtering by employee. - Cascade delete: removing an employee will remove related fringe records.
UML Diagram
classDiagram
class PayrollFringe {
+Guid Id
+string AddedBy
+DateTime AddedDate
+decimal CashFringe
+decimal Dental
+decimal Disability
+decimal EAP
+decimal Health
+decimal Holiday
+decimal TotalFringe
+Guid EmployeeId
}
class Employee {
+Guid EmployeeId
+string DisplayName
+string JdeNumber
// ...other props
}
Employee "1" <-- "0..*" PayrollFringe : "EmployeeId"
⚙️ How It Works
-
Migration Creation
- You run:
dotnet ef migrations add AddFringeTable - EF Core scaffolds two files:
20241202161634_AddFringeTable.cs(Up/Down operations)20241202161634_AddFringeTable.Designer.cs(model snapshot)
- You run:
-
Model Snapshot
- The Designer file captures all entity definitions—ensuring EF knows the current model shape for future diffs.
- Never manually edit the designer file; it will be overwritten on each new migration.
-
Applying Migration
dotnet ef database update- EF compares the snapshot to the live database and applies pending changes (e.g., creating
PayrollFringe).
- EF compares the snapshot to the live database and applies pending changes (e.g., creating
🚀 Usage & Examples
Querying Fringe Data
using(var ctx = new IrbyContext())
{
// Fetch fringe records for a specific employee
var fringes = ctx.Set<PayrollFringe>()
.Where(f => f.EmployeeId == someEmployeeId)
.OrderByDescending(f => f.AddedDate)
.ToList();
}
Adding a Fringe Entry
var entry = new PayrollFringe {
EmployeeId = employee.Id,
AddedBy = currentUser,
AddedDate = DateTime.UtcNow,
HoursWorked = 40m,
HourlyRate = 25m,
Health = 150m,
Dental = 50m,
TotalFringe = 200m,
// ... fill other fringe components ...
};
ctx.Add(entry);
ctx.SaveChanges();
🏁 Conclusion
- The
AddFringeTable.Designer.csfile is a critical part of EF Core’s migrations pipeline. - It snapshots your entire model to ensure accurate diffs across future schema changes.
- Key deliverable: introduction of the
PayrollFringetable with comprehensive fringe‐benefit tracking columns and a robust FK relationship toEmployee. - Next Steps: embrace migrations for all schema changes, keep your domain classes in sync, and leverage EF Core’s powerful tooling for smooth database evolution.
Happy coding! 🚀