๐Ÿ“š Documentation: Migration AddWorkOrderTable

File: IrbyImaging.DbContext/Migrations/20240229202700_AddWorkOrderTable.cs


๐Ÿ“‘ Table of Contents

  1. ๐Ÿ”– Overview & Purpose
  2. ๐Ÿ› ๏ธ Dependencies & Technologies
  3. ๐Ÿ’พ Data Model: WorkOrder
    • 3.1 ๐Ÿ“ Columns & Types
    • 3.2 ๐Ÿ”‘ Constraints
  4. ๐Ÿ”ง Migration Methods
    • 4.1 โž• Up()
    • 4.2 โž– Down()
  5. ๐Ÿงฉ Thirdโ€Party Integrations
  6. ๐Ÿ“Š UML Diagram
  7. ๐Ÿš€ Usage Example
  8. ๐Ÿ” Rollback & Versioning Strategy
  9. โš™๏ธ Helper Methods / Utilities
  10. โ— Error Handling & Return Types
  11. ๐ŸŒ API Endpoints Overview
  12. ๐Ÿ“ Conclusion

1. ๐Ÿ”– Overview & Purpose

This Entity Framework Core migration introduces a new table named WorkOrder in the irby schema.

  • Intent: Store and manage work orders (projects, jobs) in the database.
  • Scope: Defines all relevant columns, data types, nullability, and a primary key.
  • Usage: Executed via EF Core CLI or Package Manager Console to upgrade/downgrade your database schema.

2. ๐Ÿ› ๏ธ Dependencies & Technologies

Technology Version / Notes
.NET / .NET Core 6.0+ recommended
C# 10.0+
Microsoft.EntityFrameworkCore >= 5.0 (Migrations support)
Microsoft.EntityFrameworkCore.Tools CLI tooling for dotnet ef

3. ๐Ÿ’พ Data Model: WorkOrder

3.1 ๐Ÿ“ Columns & Types

Column Name CLR Type SQL Type Nullable Description
WorkOrderId Guid uniqueidentifier No Primary key, unique ID for work order
Org_Bu string nvarchar(max) Yes Organization Business Unit
Org_IntDivision string nvarchar(max) Yes Internal division identifier
Name string nvarchar(max) Yes Friendly name of the work order
DisplayName string nvarchar(max) Yes Display name for UI
WorkOrderNumber string nvarchar(max) Yes Business reference number
DocType string nvarchar(max) Yes Document type
WorkOrderType string nvarchar(max) Yes Category or type of work order
Status string nvarchar(max) Yes Current status (e.g., Open, Closed)
Reference string nvarchar(max) Yes External reference link/ID
EstimatedHours decimal decimal(18,2) No Hours estimated for completion
EstimatedAmount decimal decimal(18,2) No Cost estimate
DateAssigned DateTime? datetime2 Yes When work was assigned
DateStart DateTime? datetime2 Yes Planned or actual start date
DateComplete DateTime? datetime2 Yes Completion date
StatusComment string nvarchar(max) Yes Notes or comments on status
JobId Guid uniqueidentifier No Foreign key to associated Job
EquipmentId Guid? uniqueidentifier Yes FK to equipment used (if any)
ProjectManagerId Guid? uniqueidentifier Yes FK to user/employee managing it

3.2 ๐Ÿ”‘ Constraints

  • Primary Key:
    • PK_WorkOrder (WorkOrderId)
  • Schema:
    • All columns live under the irby database schema:
      CREATE TABLE irby.WorkOrder ( ... );
      
  • Foreign Keys (implicit, must be added via subsequent migrations or model configuration if desired).

4. ๐Ÿ”ง Migration Methods

EF Core migrations define two essential methods:

4.1 โž• Up()

Applies the migrationโ€”creates the new table.

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.CreateTable(
        name: "WorkOrder",
        schema: "irby",
        columns: table => new
        {
            WorkOrderId      = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
            Org_Bu           = table.Column<string>(type: "nvarchar(max)",       nullable: true),
            /* ... other columns ... */
            ProjectManagerId = table.Column<Guid>(type: "uniqueidentifier",    nullable: true)
        },
        constraints: table =>
        {
            table.PrimaryKey("PK_WorkOrder", x => x.WorkOrderId);
        });
}

4.2 โž– Down()

Rolls back the migrationโ€”drops the table.

protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.DropTable(
        name: "WorkOrder",
        schema: "irby");
}

5. ๐Ÿงฉ Thirdโ€Party Integrations

  • Entity Framework Core:
    • Uses MigrationBuilder from Microsoft.EntityFrameworkCore.Migrations.
  • SQL Server (implied by uniqueidentifier, nvarchar, datetime2 types).

6. ๐Ÿ“Š UML Diagram

classDiagram
    class WorkOrder {
        +Guid WorkOrderId
        +string Org_Bu
        +string Org_IntDivision
        +string Name
        +string DisplayName
        +string WorkOrderNumber
        +string DocType
        +string WorkOrderType
        +string Status
        +string Reference
        +decimal EstimatedHours
        +decimal EstimatedAmount
        +DateTime? DateAssigned
        +DateTime? DateStart
        +DateTime? DateComplete
        +string StatusComment
        +Guid JobId
        +Guid? EquipmentId
        +Guid? ProjectManagerId
    }

7. ๐Ÿš€ Usage Example

  1. Add Migration
    dotnet ef migrations add AddWorkOrderTable
    
  2. Apply to Database
    dotnet ef database update
    
  3. Inspect Schema
    -- In SSMS or Azure Data Studio:
    SELECT * FROM irby.WorkOrder;
    

8. ๐Ÿ” Rollback & Versioning Strategy

  • Downgrade to previous migration:
    dotnet ef database update LastGoodMigrationName
    
  • Remove the AddWorkOrderTable migration (if unneeded):
    dotnet ef migrations remove
    

9. โš™๏ธ Helper Methods / Utilities

N/A
This migration file contains only the standard EF Core Up/Down methods and no additional helper code.


10. โ— Error Handling & Return Types

  • EF Core Migrations automatically wrap schema changes in transactions.
  • If table creation fails, the migration will rollback to maintain schema integrity.

11. ๐ŸŒ API Endpoints Overview

Not Applicable
This is a dataโ€layer migration; there are no direct API endpoints here.


12. ๐Ÿ“ Conclusion

The AddWorkOrderTable migration is a critical step in extending the IrbyImaging database model to support comprehensive workโ€order management. By defining all necessary columns, data types, and the primary key, it lays the groundwork for business logic and UI layers to interact with work orders seamlessly.

๐Ÿš€ Next Steps:

  • Define EF Core model class WorkOrder with navigation properties.
  • Configure relationships (Job, Equipment, ProjectManager) in your DbContext.
  • Scaffold/update APIs or UI components to CRUD WorkOrder records.

Generated with โค๏ธ to help you understand and utilize your EF Core migration!