20250116161541_CostCodeNumberChange.Designer.cs
# 📦 Migration Documentation:
IrbyImaging.DbContext/Migrations/20250116161541_CostCodeNumberChange.Designer.cs
---
## Table of Contents
1. [Overview & Purpose](#1-overview--purpose)
2. [EF Core Migration Primer](#2-ef-core-migration-primer)
3. [File Structure & Attributes](#3-file-structure--attributes)
4. [`BuildTargetModel` Method](#4-buildtargetmodel-method)
5. [Key Entity: **CostCode**](#5-key-entity-costcode)
6. [Other Entities at a Glance](#6-other-entities-at-a-glance)
7. [Relationships & Navigation](#7-relationships--navigation)
8. [Annotations & Value Conversions](#8-annotations--value-conversions)
9. [Applying & Rolling Back](#9-applying--rolling-back)
10. [UML Diagram (Simplified)](#10-uml-diagram-simplified)
11. [Conclusion](#11-conclusion)
---
## 1. Overview & Purpose
This file is the **auto‑generated snapshot** of your EF Core model **after** the
`20250116161541_CostCodeNumberChange` migration is applied.
- **Namespace**: `IrbyImaging.DbContext.Migrations`
- **Class**: `partial class CostCodeNumberChange`
- **Role**: Captures how **every** `DomainClasses.*` maps to your SQL schema.
- **Focus of This Migration**: Adjust the `CostCode` entity’s `CostCodeNumber` column to meet new business requirements.
---
## 2. EF Core Migration Primer 📚
Entity Framework Core Migrations help you evolve your database schema alongside your C# model:
- **Add Migration**: scaffolds **Up**/**Down** logic + a **Designer** snapshot.
- **Designer File**: does **not** contain DDL code; instead it reconstructs the **entire** model.
- **Why It Matters**: EF uses this snapshot to compute diffs when future migrations are created.
---
## 3. File Structure & Attributes
```csharp
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace IrbyImaging.DbContext.Migrations
{
[DbContext(typeof(IrbyContext))]
[Migration("20250116161541_CostCodeNumberChange")]
partial class CostCodeNumberChange
{
protected override void BuildTargetModel(ModelBuilder modelBuilder) { … }
}
}
[DbContext(typeof(IrbyContext))]→ Links to your EF context[Migration("…")]→ Unique timestamp + name- Imports: core EF namespaces for metadata & migrations
4. BuildTargetModel Method 🔧
Reconstructs your post‑migration EF model:
- Global Annotations
- Entity Definitions
- Property Mappings (types, lengths, keys)
- Relationships (HasOne/WithMany)
- Inheritance / Discriminators (TPH for assets)
Sample Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.CostCode", b =>
{
b.Property<Guid>("CostCodeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CostCodeNumber")
.HasColumnType("nvarchar(max)");
b.Property<Guid>("JobId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("CostCodeId");
b.HasIndex("JobId");
b.ToTable("CostCode", "irby");
});
5. Key Entity: CostCode
| Property | CLR Type | SQL Type | Description |
|---|---|---|---|
| CostCodeId | Guid |
uniqueidentifier |
PK, auto-generated |
| CostCodeNumber | string |
nvarchar(max) |
Updated by this migration |
| JobId | Guid |
uniqueidentifier |
FK → Job |
| Name | string |
nvarchar(max) |
Cost code description |
🔍 Focus: This migration renames or alters the
CostCodeNumbercolumn to improve clarity/separation from the classicCostCodefield.
6. Other Entities at a Glance
This snapshot covers 100+ domain classes. A few categories:
| Domain Area | Sample Entities |
|---|---|
| Accounting | AccountBalances, AccountLedger, BillingInvoice |
| Audit & Security | AuditDetail, LinkUserRole, Permissions |
| Assets & Equip. | Asset (TPH), Equipment, EquipmentTimesheet |
| Jobs & Contracts | Job, ContractTypeDetails, CostCode, JobClassification |
| HR & Payroll | Employee, Department, TimeSheetEntry, PayrollFringe |
| Documents | DocumentImage, DocumentAttribute, TempDocumentData |
| Field Ops | FieldOffice, FieldTimesheet, WorkEntry |
| Support | Ticket, Update |
7. Relationships & Navigation 🔗
EF Core DSL expresses foreign keys & collections:
// CostCode → Job (many-to-one):
modelBuilder.Entity("…CostCode", b =>
{
b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
.WithMany()
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
- Cascade Deletes: Deleting a
Jobremoves itsCostCodeentries. - TPH Inheritance:
Assetbase with subtypes (Computer,MobileDevice, etc.) via.HasDiscriminator().
8. Annotations & Value Conversions 🏷️
.HasAnnotation("ProductVersion","9.0.0").HasAnnotation("Relational:MaxIdentifierLength",128)- Identity Columns:
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); // And on individual int keys: UseIdentityColumn() - ValueConverters: none explicitly here (would appear as
.HasConversion(...)).
9. Applying & Rolling Back 🔄
# Add & scaffold the migration
dotnet ef migrations add CostCodeNumberChange
# Update your database
dotnet ef database update
# To rollback one step
dotnet ef database update LastGoodMigrationName
⚠️ Always backup before applying schema changes!
10. UML Diagram (Simplified)
classDiagram
class Job {
+Guid JobId
+string Name
}
class CostCode {
+Guid CostCodeId
+string CostCodeNumber
+string Name
}
Job --* CostCode : has >
11. Conclusion 🎯
- This Designer file is critical for EF Core’s migration engine.
- It heeds the full shape of your model after the
CostCodeNumberChange. - Do not edit manually—any change is overwritten on the next scaffold.
- The actual DDL operations (column renames, etc.) live in
20250116161541_CostCodeNumberChange.cs(Up/Down methods).
✨ Happy coding! ✨