📑 AddDocumentIdToWorkOrder.Designer.cs Documentation

Location: IrbyImaging.DbContext/Migrations/20240802135205_AddDocumentIdToWorkOrder.Designer.cs
Generated by: Entity Framework Core 7.0.7
Purpose: Model snapshot after applying the AddDocumentIdToWorkOrder migration


🗂 Table of Contents

  1. 📖 Overview & Purpose
  2. ⚙️ Migration Context
  3. 🔎 BuildTargetModel Method
  4. 🗄️ WorkOrder Entity Changes
  5. 🔄 Applying & Rolling Back the Migration
  6. 🛠️ Code Snippets & Usage Examples
  7. 📈 Simplified UML Diagram
  8. 🚀 Next Steps & Conclusion

📖 Overview & Purpose

This file is an auto‑generated snapshot of the Entity Framework Core (EF Core) model after the AddDocumentIdToWorkOrder migration.

  • It lives alongside the hand‑written migration (AddDocumentIdToWorkOrder.cs) and contains the BuildTargetModel(ModelBuilder) method.
  • EF Core uses it to compute schema differences when creating or reverting migrations.

Key Goal:

⚡️ Add a new DocumentId column to the WorkOrder table without altering existing data or relationships.


⚙️ Migration Context

Aspect Details
Migration Name 20240802135205_AddDocumentIdToWorkOrder
DbContext IrbyContext
EF Core Version 7.0.7
Database Provider Microsoft SQL Server (Identity Columns)
Schema irby
Auto‑Generated Yes
Nullable Reference TF Disabled (#nullable disable)

🔎 BuildTargetModel Method

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    #pragma warning disable 612, 618

    modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // ... (mapping for dozens of entities)
}
  • BuildTargetModel is the model snapshot after this migration.
  • It contains entity configurations, property types, keys, indexes, and relationships for every domain class.
  • Changes in this migration appear as additions to the snapshot (e.g., new properties, tables, indices).

🗄️ WorkOrder Entity Changes

New Column: DocumentId

The core purpose of this migration is reflected in the WorkOrder entity mapping:

modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
    b.Property<Guid>("WorkOrderId")
        .ValueGeneratedOnAdd()
        .HasColumnType("uniqueidentifier");

    // → NEW:
    b.Property<string>("DocumentId")
        .HasColumnType("nvarchar(max)");

    // ... other existing properties ...
    b.HasKey("WorkOrderId");
    b.HasIndex("JobId");
    b.HasIndex("ProjectManagerId");
    b.ToTable("WorkOrder", "irby");
});
  • Property: DocumentId
  • CLR Type: string
  • SQL Type: nvarchar(max)
  • Nullable: Yes (no .IsRequired() call)
  • Purpose: Link a scanned or imported document (e.g., an image blob or external document ID) to a work order

Full WorkOrder Table Schema

Column CLR Type SQL Type Notes
WorkOrderId Guid uniqueidentifier Primary Key, identity‐generated
DocumentId string nvarchar(max) NEW
DateAssigned DateTime? datetime2
DateStart DateTime? datetime2
DateComplete DateTime? datetime2
DisplayName string nvarchar(max)
DocType string nvarchar(max)
EquipmentId Guid? uniqueidentifier FK to Equipment
EstimatedHours decimal decimal(18,2)
EstimatedAmount decimal decimal(18,2)
JobId Guid uniqueidentifier FK to Job
ProjectManagerId Guid? uniqueidentifier FK to Employee
Status string nvarchar(max)
StatusComment string nvarchar(max)
Reference string nvarchar(max)
WorkOrderNumber string nvarchar(max)
WorkOrderType string nvarchar(max)

🔄 Applying & Rolling Back the Migration

Applying

# .NET CLI
dotnet ef migrations add AddDocumentIdToWorkOrder
dotnet ef database update

Or, in Package Manager Console:

Add-Migration AddDocumentIdToWorkOrder
Update-Database

Rolling Back

# To revert one migration:
dotnet ef database update 20240701120000_PreviousMigration

⚠️ Always backup your database before rolling back in production.


🛠️ Code Snippets & Usage Examples

1. Querying WorkOrder with DocumentId

// Retrieving a work order and its associated document ID
var workOrder = await context.WorkOrders
    .Where(wo => wo.WorkOrderNumber == "WO12345")
    .Select(wo => new
    {
        wo.WorkOrderId,
        wo.WorkOrderNumber,
        wo.DocumentId
    })
    .FirstOrDefaultAsync();

Console.WriteLine($"WO #{workOrder.WorkOrderNumber} → Document: {workOrder.DocumentId}");

2. Linking a Document

// Attach an external document reference
var order = await context.WorkOrders.FindAsync(someGuid);
order.DocumentId = "DOC-2024-XXXXX";
await context.SaveChangesAsync();

📈 Simplified UML Diagram

erDiagram
    WORKORDER {
        Guid   WorkOrderId PK
        string DocumentId
        Guid   JobId FK
        Guid   ProjectManagerId FK
        ...
    }
    JOB {
        Guid JobId PK
        string Name
        ...
    }
    EMPLOYEE {
        Guid EmployeeId PK
        string DisplayName
        ...
    }

    WORKORDER ||--o{ JOB             : "belongs to"
    WORKORDER }o--|| EMPLOYEE        : "managed by"
    WORKORDER }o--o{ EQUIPMENT        : "uses"

Legend:

  • PK = Primary Key
  • FK = Foreign Key
  • ||--o{ = one‑to‑many

🚀 Next Steps & Conclusion

  1. Test the updated schema by scanning or uploading documents to Work Orders.
  2. Update any business logic or API endpoints that create or query DocumentId.
  3. Document the new UI/UX behavior for linking documents in your user manuals.

Summary:
The AddDocumentIdToWorkOrder.Designer.cs file captures the EF Core model after adding a new, nullable DocumentId column to the WorkOrder table. This enables the application to associate external documents (images, PDFs, OCR metadata) with work orders going forward.

Happy coding! 🚀