π Documentation: AddPayrollMatchTable (Migration Designer)
Auto-generated EF Core migration designer file for adding, configuring, and mapping the
PayrollMatchtable in theIrbyContext.
File path:
IrbyImaging.DbContext/Migrations/20250211125043_AddPayrollMatchTable.Designer.cs
π Table of Contents
- Overview & Purpose
- Migration Structure
- BuildTargetModel Method
- Key Entity: PayrollMatch
- Entity Relationships & Indexes
- Dependencies & Technologies
- Usage Examples
- Applying & Reverting the Migration
- UML Class Diagram
- 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 theIrbyContext.[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:
- Global Annotations
modelBuilder .HasAnnotation("ProductVersion", "9.0.0") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - Entity Definitions
Repeats for every domain class underIrbyImaging.DomainClasses.*. - Property Mappings
.Property<T>("ColumnName") .HasColumnType("sqlType") [...] - Keys & Indexes
b.HasKey("Id")b.HasIndex("ForeignKey")
- Relationships
HasOne(...).WithMany(...).HasForeignKey(...).OnDelete(...)
- Global Annotations
πΌ 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
EmployeeIdfor 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.
- Solid arrow:Β
π― 10. Conclusion
- This designer file is a snapshot of your EF model after adding the
PayrollMatchtable. - It drives EF Coreβs ability to generate Up/Down migrations reliably.
- Key takeaway: Review
BuildTargetModelto understand how EF Core perceives your domain schema, constraints, and relationships.
Happy coding! π