📚 AddFKToWorkOrderTable.Designer.cs Documentation
📑 Table of Contents
- 📝 Overview & Purpose
- ⚙️ Dependencies & Technologies
- 🔑 Key Functional Areas
3.1. BuildTargetModel Method
3.2. Entity Definitions
3.3. Relationships (Foreign Keys) - 📊 Data Models Highlight: WorkOrder
- 🛠️ Helper Methods & Utilities
- 🚚 Third‑party Integrations
- 🖥️ Sample Code Blocks
- 📈 UML Diagram
- 📖 Conclusion
📝 1. Overview & Purpose
AddFKToWorkOrderTable.Designer.cs is an auto‑generated snapshot of the Entity Framework Core model at the point of the 20240229203206_AddFKToWorkOrderTable migration. Its main responsibilities are:
- Building the target model via
ModelBuilderso EF Core knows what the database schema should look like after applying this migration. - Defining all entities, their properties, keys, indexes, and relational mappings.
- Introducing foreign key relationships—in particular, adding references from WorkOrder to Equipment, Job, and Employee.
⚠️ Do not modify this file by hand. It is regenerated whenever you scaffold or update migrations.
⚙️ 2. Dependencies & Technologies
| Dependency | Version | Role |
|---|---|---|
| Microsoft.EntityFrameworkCore | 7.0.7 | Core ORM framework |
| Microsoft.EntityFrameworkCore.SqlServer | 7.x | SQL Server-specific extensions |
| Microsoft.EntityFrameworkCore.Relational | 7.x | Relational database abstractions |
| Microsoft.EntityFrameworkCore.Infrastructure | 7.x | Context and design-time services |
🔑 3. Key Functional Areas
3.1 BuildTargetModel Method
[DbContext(typeof(IrbyContext))]
[Migration("20240229203206_AddFKToWorkOrderTable")]
partial class AddFKToWorkOrderTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// ... auto-generated entity configurations ...
}
}
- Signature
protected override void BuildTargetModel(ModelBuilder modelBuilder) - Purpose
Builds an in‑memory snapshot of your EF Core model that matches the database schema after this migration is applied.
3.2 Entity Definitions
Inside BuildTargetModel, each call to modelBuilder.Entity(...) configures:
- Properties: type, column name, nullability, max length.
- Keys: primary keys via
.HasKey(). - Indexes: via
.HasIndex(). - Table mapping: via
.ToTable()with optional schema. - Discriminators: for TPH inheritance (
Asset,Computer,MobileDevice, etc.).
There are 60+ entity types declared; we focus on WorkOrder below.
3.3 Relationships (Foreign Keys)
The purpose of this migration is to ensure WorkOrder has proper FKs:
- WorkOrder → Equipment
- FK property:
EquipmentId - Optional relationship (
.HasOne(...).HasForeignKey("EquipmentId"))
- FK property:
- WorkOrder → Job
- FK property:
JobId - Required relationship (
OnDelete(DeleteBehavior.Cascade))
- FK property:
- WorkOrder → Employee
- FK property:
ProjectManagerId - Optional (“ProjectManager” nav property)
- FK property:
📊 4. Data Models Highlight: WorkOrder
| Property Name | CLR Type | Column Type | Description |
|---|---|---|---|
| WorkOrderId (PK) | Guid | uniqueidentifier | Primary Key |
| DateAssigned | DateTime? | datetime2 | When assignment occurred |
| DateStart | DateTime? | datetime2 | Planned start date |
| DateComplete | DateTime? | datetime2 | Actual completion date |
| DisplayName | string | nvarchar(max) | User‑friendly name |
| DocType | string | nvarchar(max) | Document type |
| EquipmentId (FK) | Guid? | uniqueidentifier | References Equipment |
| EstimatedAmount | decimal (18,2) | decimal(18,2) | Cost estimate |
| EstimatedHours | decimal (18,2) | decimal(18,2) | Time estimate |
| JobId (FK) | Guid | uniqueidentifier | References Job |
| ProjectManagerId | Guid? | uniqueidentifier | References Employee (PM) |
| Reference | string | nvarchar(max) | External reference |
| Status | string | nvarchar(max) | Current status |
| StatusComment | string | nvarchar(max) | Notes on status |
| WorkOrderNumber | string | nvarchar(max) | Unique order number |
| WorkOrderType | string | nvarchar(max) | Type/category of work order |
Navigation Properties on WorkOrder:
Equipment➔IrbyImaging.DomainClasses.EquipmentJob➔IrbyImaging.DomainClasses.JobEmployee(Project Manager) ➔IrbyImaging.DomainClasses.Employee
🛠️ 5. Helper Methods & Utilities
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
Enables SQL Server IDENTITY pattern for auto‑incremented integer keys.b.Property<int>("Id").ValueGeneratedOnAdd()
Configures a property to have its value generated by the database.
🚚 6. Third‑party Integrations
- Entity Framework Core: Mapping .NET classes to a SQL Server schema.
- SQL Server: Relational database engine; uses
datetime2,uniqueidentifier,decimal(18,2), etc.
🖥️ 7. Sample Code Blocks
WorkOrder Entity Configuration
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.Property<Guid>("WorkOrderId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("EquipmentId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("JobId")
.IsRequired()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("ProjectManagerId")
.HasColumnType("uniqueidentifier");
// Primary Key
b.HasKey("WorkOrderId");
// Indexes for FKs
b.HasIndex("EquipmentId");
b.HasIndex("JobId");
b.HasIndex("ProjectManagerId");
// Table
b.ToTable("WorkOrder", "irby");
});
Relationship Mapping
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.HasOne("IrbyImaging.DomainClasses.Equipment", "Equipment")
.WithMany()
.HasForeignKey("EquipmentId");
b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
.WithMany()
.IsRequired()
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
.WithMany()
.HasForeignKey("ProjectManagerId");
});
📈 8. UML Diagram
classDiagram
WorkOrder <-- Equipment : EquipmentId (optional)
WorkOrder <-- Job : JobId (required)
WorkOrder <-- Employee : ProjectManagerId (optional)
class WorkOrder {
+Guid WorkOrderId
+DateTime? DateAssigned
+DateTime? DateStart
+DateTime? DateComplete
+string DisplayName
+string DocType
+decimal EstimatedAmount
+decimal EstimatedHours
+string Status
+string StatusComment
+string WorkOrderNumber
+string WorkOrderType
}
class Equipment {
+Guid EquipmentId
+string Name
+Guid JobId
// …other properties…
}
class Job {
+Guid JobId
+string Name
+Guid? FieldOfficeId
// …other properties…
}
class Employee {
+Guid EmployeeId
+string FirstName
+string LastName
// …other properties…
}
📖 9. Conclusion
-
What this file is for
It’s a snapshot used by EF Core Migrations to understand how to transition your database from the previous model to the new model—specifically adding FKs on the WorkOrder table. -
When it runs
Duringdotnet ef database update, EF Core reads this designer file to apply theUp()andDown()methods in the corresponding migration, ensuring your database schema matches your C# domain model. -
User Guidance
• Do not edit manually.
• If you change your domain classes, scaffold a new migration (dotnet ef migrations add <Name>).
• Version‑control these files to keep track of schema changes over time.
Happy coding! 🚀