πŸ“‘ Table of Contents

  1. πŸ“– Overview & Purpose
  2. πŸ”‘ Key Functional Areas
  3. πŸ›  Dependencies & Technologies
  4. πŸ—„ Data Model Entities
    4.1 WorkOrder Table
    4.2 Snapshot of Other Entities (Summary)
  5. πŸ“ UML Class Diagram
  6. πŸš€ Applying the Migration
  7. πŸ’» Sample Code Snippets
  8. πŸ“š 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 migrations tooling 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.
  • 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.
  • Relationships
    • HasOne/WithMany calls 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

  1. Restore & Build
    dotnet restore
    dotnet build
    
  2. Add Migration (if you’re creating a new one)
    dotnet ef migrations add AddWorkOrderTable
    
  3. Update Database
    dotnet ef database update
    
    This will execute the Up() logic (in the corresponding .cs file) and update the schema, including irby.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.