π Table of Contents
- π Overview & Purpose
- π Key Functional Areas
- π Dependencies & Technologies
- π Data Model Entities
4.1 WorkOrder Table
4.2 Snapshot of Other Entities (Summary) - π UML Class Diagram
- π Applying the Migration
- π» Sample Code Snippets
- π Conclusion
π Overview & Purpose
This fileβAddWorkOrderTable.Designer.csβis an auto-generated EF Core migration designer for the AddWorkOrderTable migration (timestamp: 20240229202700). It lives in the IrbyImaging.DbContext.Migrations namespace and defines the target model of your database after the migration is applied.
- It does not contain the
Up()/Down()methods (which add or remove schema objects). - Instead, it rebuilds the full EF Core model snapshot via the
BuildTargetModel(ModelBuilder modelBuilder)method. - This snapshot is compared by EF Core to your current model to generate SQL operations.
Why it matters:
- Ensures EFβs design-time tools know exactly how your C# classes map to SQL tables.
- Helps maintain consistency across different dev machines and CI pipelines.
- Enables
dotnet ef migrationstooling to scaffold future migrations correctly.
π Key Functional Areas
- BuildTargetModel
- Registers all entities, properties, keys, and relationships into the
ModelBuilder. - Applies table mappings, column types, constraints, indices, discriminator strategies (TPT/TPC/TPH), and schemas.
- Registers all entities, properties, keys, and relationships into the
- Annotations & Conventions
.HasAnnotation("ProductVersion", "7.0.7").UseIdentityColumns()for SQL Server identity strategy.
- Entity Definitions
- Hundreds of
modelBuilder.Entity("Namespace.ClassName", b => { β¦ })blocks representing your domain classes. - One new table: WorkOrder under the
"irby"schema.
- Hundreds of
- Relationships
HasOne/WithManycalls set up navigation properties and foreignβkey constraints.
π Dependencies & Technologies
| Technology | Version / Notes |
|---|---|
| .NET SDK | 7.0.7 |
| Entity Framework Core | EF Core 7 (Microsoft.EntityFrameworkCore) |
| Database Provider | Microsoft.EntityFrameworkCore.SqlServer |
| Migrations Assembly | IrbyImaging.DbContext.Migrations |
| Language | C# 11 / Nullable disabled (#nullable disable) |
π Data Model Entities
WorkOrder Table
π Newly added entity by this migration
| Column Name | CLR Type | SQL Type | Constraints |
|---|---|---|---|
| WorkOrderId | Guid | uniqueidentifier | Primary Key, ValueGeneratedOnAdd |
| DateAssigned | DateTime? | datetime2 | |
| DateStart | DateTime? | datetime2 | |
| DateComplete | DateTime? | datetime2 | |
| Name | string | nvarchar(max) | |
| DisplayName | string | nvarchar(max) | |
| WorkOrderNumber | string | nvarchar(max) | |
| WorkOrderType | string | nvarchar(max) | |
| DocType | string | nvarchar(max) | |
| Reference | string | nvarchar(max) | |
| Status | string | nvarchar(max) | |
| StatusComment | string | nvarchar(max) | |
| EstimatedHours | decimal (18,2) | decimal(18,2) | |
| EstimatedAmount | decimal (18,2) | decimal(18,2) | |
| JobId | Guid | uniqueidentifier | Required, FK to Job |
| EquipmentId | Guid? | uniqueidentifier | Optional FK to Equipment |
| Org_Bu | string | nvarchar(max) | |
| Org_IntDivision | string | nvarchar(max) | |
| ProjectManagerId | Guid? | uniqueidentifier | Optional FK to Employee |
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.Property<Guid>("WorkOrderId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<DateTime?>("DateAssigned").HasColumnType("datetime2");
// β¦ other properties β¦
b.HasKey("WorkOrderId");
b.ToTable("WorkOrder", "irby");
});
Relationships (configured elsewhere in the designer snapshot):
- WorkOrder β Job (
JobId, required, cascade on delete). - WorkOrder β Equipment (
EquipmentId, optional). - WorkOrder β Employee (
ProjectManagerId, optional).
Snapshot of Other Entities (Summary)
This migration snapshot also contains all domain entities as they existed at the time, for example:
- Asset family (TPH: Computer, DeskPhone, Dock, MobileDevice, β¦)
- Employee, Job, FieldOffice and associated lookups
- DocumentImage, TempDocumentData, BlobData
- Ticket & Update, TimeSheetEntry & TimeEntryType
- GeneralLedger, GLTypeDetail, BillingInvoice, PurchaseOrder
- CarrierType & CarrierTypeDetail, Permissions, LinkUserRole, etc.
β οΈ You generally do not need to read or modify these sectionsβEF Core manages them.
π UML Class Diagram
classDiagram
class WorkOrder {
+Guid WorkOrderId
+DateTime? DateAssigned
+DateTime? DateStart
+DateTime? DateComplete
+string Name
+string DisplayName
+string WorkOrderNumber
+string WorkOrderType
+string DocType
+string Reference
+string Status
+string StatusComment
+decimal EstimatedHours
+decimal EstimatedAmount
}
class Job
class Equipment
class Employee
WorkOrder --|> Job : JobId
WorkOrder --|> Equipment : EquipmentId
WorkOrder --|> Employee : ProjectManagerId
π Applying the Migration
- Restore & Build
dotnet restore dotnet build - Add Migration (if youβre creating a new one)
dotnet ef migrations add AddWorkOrderTable - Update Database
This will execute thedotnet ef database updateUp()logic (in the corresponding.csfile) and update the schema, includingirby.WorkOrder.
π» Sample Code Snippets
1. Querying Work Orders
using var context = new IrbyContext();
var pending = await context.WorkOrders
.Where(w => w.Status == "Pending")
.Include(w => w.Job)
.ToListAsync();
2. Creating a New Work Order
var wo = new DomainClasses.WorkOrder {
Name = "Inspect Generator",
WorkOrderType = "Inspection",
JobId = jobId,
EstimatedHours = 2,
EstimatedAmount = 150.00m,
Status = "New"
};
context.WorkOrders.Add(wo);
await context.SaveChangesAsync();
π Conclusion
The AddWorkOrderTable.Designer.cs is a critical part of the EF Core migrations infrastructure, capturing the entire model snapshot after the AddWorkOrderTable migration. It ensures that EF Core has full knowledge of your domain classes, table mappings, and relationships for accurate SQL generation and subsequent migrations.
π Tip: Treat designer files as readβonlyβcustom changes belong in the primary migration (.cs) or your DbContext configuration.