š Documentation for 20240801143541_AddWorkOrderType.Designer.cs
AutoāGenerated EF Core Migration Designer
Namespace:IrbyImaging.DbContext.Migrations
Context:IrbyContext
Migration:20240801143541_AddWorkOrderType
š Table of Contents
- Overview & Purpose
- Migration Metadata
- BuildTargetModel Method
- Change Summary: Add
WorkOrderType - Running & Applying the Migration
- Working with the New Property in Code
- 6.1 Domain Class Snippet
- 6.2 CRUD Example
- UML Class Diagram
- Dependencies & Technologies
- Conclusion
1. Overview & Purpose
This file is an EF Core Designer snapshot generated by the [dotnet ef migrations add] operation. It contains the target model (i.e., the full database schema in code) after the AddWorkOrderType migration has been applied.
- It should not be handāedited.
- EF Core uses it at designātime to compare model differences and scaffold future migrations.
The key purpose of AddWorkOrderType.Designer.cs is to record:
- All entities & their properties
- Keys, indexes, discriminators (for TPH inheritance)
- Relationships and navigation properties
- The newly introduced
WorkOrderTypecolumn on theWorkOrdertable
2. Migration Metadata
| Attribute | Value |
|---|---|
DbContext |
IrbyContext |
Migration Id |
20240801143541_AddWorkOrderType |
Product Version (EF Core) |
7.0.7 |
MaxIdentifierLength |
128 |
Provider |
Microsoft.EntityFrameworkCore.SqlServer (implied) |
Identity Strategy |
UseIdentityColumns |
[DbContext(typeof(IrbyContext))]
[Migration("20240801143541_AddWorkOrderType")]
partial class AddWorkOrderType
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// ⦠entity configurations follow ā¦
}
}
3. BuildTargetModel Method
The BuildTargetModel method reconstructs the complete EF Core model as a series of fluentāAPI calls on ModelBuilder.
3.1 Model Annotations
- ProductVersion: Tracks the EF Core version used to generate the model.
- Relational:MaxIdentifierLength: Ensures compatibility with SQL Serverās 128ācharacter limit.
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
3.2 Entity Configurations
š Example:
WorkOrderEntity
(Only the relevant properties are shown; the full file defines 60+ entities.)
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.Property<Guid>("WorkOrderId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("WorkOrderNumber")
.HasColumnType("nvarchar(max)");
b.Property<string>("Status")
.HasColumnType("nvarchar(max)");
// NEW in this migration
b.Property<string>("WorkOrderType")
.HasColumnType("nvarchar(max)");
b.HasKey("WorkOrderId");
b.HasIndex("JobId");
b.HasIndex("ProjectManagerId");
b.ToTable("WorkOrder", "irby");
});
Other entities include Asset, Employee, Job, DocumentImage, TempDocumentData, etc. Each is defined with:
- Properties (
b.Property<T>(ā¦)) - Keys (
b.HasKey(ā¦)) - Indexes (
b.HasIndex(ā¦)) - Table Mappings (
b.ToTable(ā¦)) - Discriminators for TPH inheritance (
b.HasDiscriminator(ā¦))
3.3 Relationships & Navigations
Relationships between entities are configured at the bottom of the BuildTargetModel method. Example:
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");
b.Navigation("Employee");
b.Navigation("Job");
});
4. Change Summary: Add WorkOrderType
This migrationās sole purpose is to introduce a new string column named WorkOrderType to the WorkOrder table:
| Table | Column | CLR Type | SQL Type | Allows Nulls |
|---|---|---|---|---|
WorkOrder |
WorkOrderType |
string |
nvarchar(max) |
Yes |
Impact
- All existing
WorkOrderrecords will haveNULLinWorkOrderTypeuntil updated.- Developers can categorize work orders by type (e.g., āInspectionā, āRepairā, āMaintenanceā).
5. Running & Applying the Migration
5.1 Add & Update Database
- Add Migration (already done):
dotnet ef migrations add AddWorkOrderType - Apply to Database:
dotnet ef database updateThis will apply 20240801143541_AddWorkOrderType, adding the new column.
5.2 CLI / PMC Examples
- Package Manager Console
Add-Migration AddWorkOrderType Update-Database - .NET CLI
dotnet ef migrations add AddWorkOrderType dotnet ef database update
6. Working with the New Property in Code
6.1 Domain Class Snippet
Ensure the domain entity WorkOrder in IrbyImaging.DomainClasses is updated:
public class WorkOrder
{
public Guid WorkOrderId { get; set; }
public string WorkOrderNumber { get; set; }
public string Status { get; set; }
// Newly added:
public string? WorkOrderType { get; set; }
// Navigation:
public Job Job { get; set; }
public Employee? ProjectManager { get; set; }
}
6.2 CRUD Example
// 1. Creating a new WorkOrder with a type
var workOrder = new WorkOrder {
WorkOrderNumber = "WO-12345",
Status = "Open",
WorkOrderType = "Inspection",
JobId = existingJobId
};
context.WorkOrders.Add(workOrder);
await context.SaveChangesAsync();
// 2. Query by WorkOrderType
var inspections = await context.WorkOrders
.Where(wo => wo.WorkOrderType == "Inspection")
.ToListAsync();
7. UML Class Diagram
classDiagram
class WorkOrder {
+Guid WorkOrderId
+string WorkOrderNumber
+string Status
+string? WorkOrderType
+DateTime? DateAssigned
+DateTime? DateStart
+DateTime? DateComplete
}
WorkOrder --> Job : JobId
WorkOrder --> Employee : ProjectManagerId
āļø Mermaid diagram showing the
WorkOrderentity, its key properties, and relationships.
8. Dependencies & Technologies
- .NET 7 (C#)
- Entity Framework Core 7.0.7
- Microsoft.EntityFrameworkCore.SqlServer
- EF Core Migrations (Designer Annotations)
- SQL Server (Relational Database)
9. Conclusion
This Designer file is a snapshot of your EF Core model after applying the AddWorkOrderType migration. It records:
- All entities, properties, indexes, keys, and relationships
- The new
WorkOrderTypecolumn on theWorkOrdertable
Keep your domain classes and migration files in sync. After applying the migration:
- Update your
WorkOrderdomain class with the new property. - Use LINQ to CRUD or filter by
WorkOrderType. - Rerun
dotnet ef migrations addfor future schema changesāEF will diff against this snapshot.
Happy coding! š