๐ Documentation: Migration AddWorkOrderTable
File: IrbyImaging.DbContext/Migrations/20240229202700_AddWorkOrderTable.cs
๐ Table of Contents
- ๐ Overview & Purpose
- ๐ ๏ธ Dependencies & Technologies
- ๐พ Data Model: WorkOrder
- 3.1 ๐ Columns & Types
- 3.2 ๐ Constraints
- ๐ง Migration Methods
- 4.1 โ
Up() - 4.2 โ
Down()
- 4.1 โ
- ๐งฉ ThirdโParty Integrations
- ๐ UML Diagram
- ๐ Usage Example
- ๐ Rollback & Versioning Strategy
- โ๏ธ Helper Methods / Utilities
- โ Error Handling & Return Types
- ๐ API Endpoints Overview
- ๐ 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
irbydatabase schema:CREATE TABLE irby.WorkOrder ( ... );
- All columns live under the
- 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
MigrationBuilderfromMicrosoft.EntityFrameworkCore.Migrations.
- Uses
- SQL Server (implied by
uniqueidentifier,nvarchar,datetime2types).
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
- Add Migration
dotnet ef migrations add AddWorkOrderTable - Apply to Database
dotnet ef database update - 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
AddWorkOrderTablemigration (if unneeded):dotnet ef migrations remove
9. โ๏ธ Helper Methods / Utilities
N/A
This migration file contains only the standard EF CoreUp/Downmethods 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
WorkOrderwith navigation properties.- Configure relationships (Job, Equipment, ProjectManager) in your
DbContext.- Scaffold/update APIs or UI components to CRUD
WorkOrderrecords.
Generated with โค๏ธ to help you understand and utilize your EF Core migration!