📚 Documentation: 20240805140229_AddTypeCodeToWorkOrder.Designer.cs
File Path:
IrbyImaging.DbContext/Migrations/20240805140229_AddTypeCodeToWorkOrder.Designer.cs
Purpose: Auto‐generated EF Core migration model snapshot reflecting the addition of a newWorkOrderTypeCodeproperty to theWorkOrderentity.
📑 Table of Contents
- ✨ Overview & Purpose
- ⚙️ Dependencies & Technologies
- 🏗️ Migration Structure
- 🔑 Key Functional Areas
- 🗂️ Model Snapshot
- 📈 Relationships & Navigation
- 🛠️ Applying the Migration
- ⚠️ Best Practices & Gotchas
- ✅ Conclusion
✨ Overview & Purpose
This Designer file is part of Entity Framework Core’s migration scaffolding. When you run:
dotnet ef migrations add AddTypeCodeToWorkOrder
EF generates three files:
20240805140229_AddTypeCodeToWorkOrder.cs20240805140229_AddTypeCodeToWorkOrder.Designer.cs- A snapshot update in your
ModelSnapshot
The Designer file contains the BuildTargetModel(ModelBuilder) method—a complete snapshot of your EF Core model after the migration. Its primary role is to allow EF to compare “before” vs. “after” models and generate accurate SQL for Up()/Down().
📌 Do NOT modify this file manually—it’s auto-generated.
⚙️ Dependencies & Technologies
| Package/Framework | Version | Purpose |
|---|---|---|
Microsoft.EntityFrameworkCore |
7.0.7 (annotation) | Core ORM |
Microsoft.EntityFrameworkCore.Infrastructure |
7.0.x | Infrastructure services |
Microsoft.EntityFrameworkCore.Metadata |
7.0.x | Model metadata |
Microsoft.EntityFrameworkCore.Migrations |
7.0.x | Migrations API |
Microsoft.EntityFrameworkCore.Storage.ValueConversion |
7.0.x | Type conversions |
.NET SDK |
≥7.0 | Platform |
SQL Server |
Any | Relational provider (Identity columns enabled) |
🏗️ Migration Structure
[DbContext(typeof(IrbyContext))]
[Migration("20240805140229_AddTypeCodeToWorkOrder")]
partial class AddTypeCodeToWorkOrder
{
// 1️⃣ BuildTargetModel: entire model after migration
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// Configurations for all entities...
}
}
[DbContext]ties this migration to yourIrbyContext.[Migration("…")]stamps the timestamp & name.BuildTargetModel: The big method that re‐creates your EF model, including the newly added column.
🔑 Key Functional Areas
-
Model Snapshot
Auto‐generated definitions for every entity, property, column type, keys & indexes. -
Identity Configuration
Usage ofUseIdentityColumns()for SQL Server identity behaviors. -
Entity Configurations
Hundreds of.Entity("Namespace.Class", b => { ... })blocks—one per domain class. -
Relationships
Fluent‐API bridging viaHasOne(),WithMany(),HasForeignKey(),OnDelete(). -
Migration Change
Addition ofWorkOrderTypeCodeto theWorkOrderentity.
🗂️ Model Snapshot
Note: The snapshot is vast; below we focus on the
WorkOrderentity and its context within the full model.
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// … hundreds of entity mappings …
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.Property<Guid>("WorkOrderId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// Existing columns…
b.Property<DateTime?>("DateAssigned").HasColumnType("datetime2");
b.Property<DateTime?>("DateComplete").HasColumnType("datetime2");
b.Property<DateTime?>("DateStart").HasColumnType("datetime2");
b.Property<string>("DisplayName").HasColumnType("nvarchar(max)");
// …
// 🔥 NEW COLUMN added by this migration
b.Property<string>("WorkOrderTypeCode")
.HasColumnType("nvarchar(max)");
b.Property<string>("WorkOrderType")
.HasColumnType("nvarchar(max)");
b.HasKey("WorkOrderId");
b.HasIndex("JobId");
b.HasIndex("ProjectManagerId");
b.ToTable("WorkOrder", "irby");
});
WorkOrder Entity (Change Highlight)
| Property | CLR Type | Column Type | Notes |
|---|---|---|---|
WorkOrderId |
Guid |
uniqueidentifier |
Primary Key, Identity |
DateAssigned |
DateTime? |
datetime2 |
Nullable |
DateStart |
DateTime? |
datetime2 |
Nullable |
DateComplete |
DateTime? |
datetime2 |
Nullable |
WorkOrderType |
string |
nvarchar(max) |
E.g. “Repair”, “Inspection” |
WorkOrderTypeCode |
string |
nvarchar(max) |
New: Short code (e.g. “INSP”, “RPR”) |
WorkOrderNumber |
string |
nvarchar(max) |
Business reference |
JobId |
Guid |
uniqueidentifier |
FK → Job(JobId) |
ProjectManagerId |
Guid? |
uniqueidentifier |
FK → Employee(EmployeeId) (nullable) |
| … (plus many more) |
📈 Relationships & Navigation
EF Core uses Fluent API to build relationships:
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
.WithMany()
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
.WithMany()
.HasForeignKey("ProjectManagerId");
});
WorkOrder → Job: Many work orders attach to one job.WorkOrder → Employee: One project manager per work order (optional).
Mermaid UML Diagram
classDiagram
class WorkOrder {
+Guid WorkOrderId
+string DisplayName
+DateTime? DateAssigned
+string WorkOrderTypeCode
+string WorkOrderType
+Guid JobId
+Guid? ProjectManagerId
}
class Job {
+Guid JobId
+string Name
+string JobNumber
}
class Employee {
+Guid EmployeeId
+string DisplayName
}
WorkOrder --> Job : JobId
WorkOrder --> Employee : ProjectManagerId
🛠️ Applying the Migration
-
Add the migration (already done):
dotnet ef migrations add AddTypeCodeToWorkOrder -
Update the database:
dotnet ef database update- EF will read the
Up()method in20240805140229_AddTypeCodeToWorkOrder.csand execute:ALTER TABLE [irby].[WorkOrder] ADD [WorkOrderTypeCode] NVARCHAR(MAX) NULL;
- EF will read the
-
Verify
- In your SQL Server:
SELECT TOP 10 WorkOrderTypeCode FROM irby.WorkOrder;
- In your SQL Server:
⚠️ Best Practices & Gotchas
- 🚫 Do not edit
.Designer.csmanually—it will be overwritten next time you scaffold. - ✔ Ensure nullable vs non-nullable alignment in your C# model and DB column.
- 🔄 After adding code references to the new column, re-build and run unit tests.
- 🧹 If working in source control, review both
AddTypeCodeToWorkOrder.csand.Designer.csfor unintended changes.
✅ Conclusion
This Designer snapshot is a crucial piece in EF Core’s migration pipeline—capturing the model state after you added WorkOrderTypeCode. It ensures accurate SQL generation and schema synchronization across environments. Remember:
- It’s auto-generated; trust EF to update it for you.
- Your business logic should reference the new
WorkOrderTypeCodeproperty from your domain model (IrbyImaging.DomainClasses.WorkOrder). - Keep migrations in source control to maintain a clear upgrade history.
Happy coding! 🚀