📄 Documentation: 20231003133244_ITDMS.cs
Location:
IrbyImaging.DbContext/Migrations/20231003133244_ITDMS.cs
📑 Table of Contents
- 🎯 Overview & Purpose
- 🛠️ Dependencies & Technologies
- 🔍 Migration Breakdown
- 🔨 Detailed Code Walkthrough
- 4.1. Up Method
- 4.2. Down Method
- ⚙️ Usage & Examples
- ⏪ Rollback & Down Migration
- 🗂️ File Structure & Location
- ✅ Conclusion
🎯 Overview & Purpose
This EF Core Migration (ITDMS) introduces fields to support IT Document Management System (ITDMS) features across existing tables in the irby schema. Specifically, it:
- Adds an
IsITflag (boolean) to multiple tables to mark “IT‑specific” records. - Introduces an
ITDocumentType(GUID) to theDocumentImagetable to link images with IT document categories.
Why?
To enable filtering, categorization, and processing of IT‑related documents and images alongside existing business document flows.
🛠️ Dependencies & Technologies
| Technology | Version/Notes |
|---|---|
| .NET / C# | .NET 6+, C# 10+ (nullable disabled) |
| Entity Framework | EF Core Migrations (Microsoft.EntityFrameworkCore.Migrations) |
| Database | SQL Server (bit, uniqueidentifier) |
🔍 Migration Breakdown
| Table | Column Name | Type | Default Value | Description |
|---|---|---|---|---|
| TempDocumentData | IsIT |
bit |
false |
Flag for IT documents |
| DocumentType | IsIT |
bit |
false |
Mark document types as IT specific |
| DocumentImage | IsIT |
bit |
false |
Mark images as IT related |
| DocumentImage | ITDocumentType |
uniqueidentifier |
00000000-0000-0000-0000-000000000000 |
FK to IT document type |
| DocumentCategory | IsIT |
bit |
false |
Flag for IT categories |
| DocumentAttribute | IsIT |
bit |
false |
Identify IT‑specific attributes |
🔨 Detailed Code Walkthrough
4.1 Up Method
protected override void Up(MigrationBuilder migrationBuilder)
{
// 1️⃣ TempDocumentData.IsIT
migrationBuilder.AddColumn<bool>(
name: "IsIT",
schema: "irby",
table: "TempDocumentData",
type: "bit",
nullable: false,
defaultValue: false);
// 2️⃣ DocumentType.IsIT
migrationBuilder.AddColumn<bool>(
name: "IsIT",
schema: "irby",
table: "DocumentType",
type: "bit",
nullable: false,
defaultValue: false);
// 3️⃣ DocumentImage.ITDocumentType
migrationBuilder.AddColumn<Guid>(
name: "ITDocumentType",
schema: "irby",
table: "DocumentImage",
type: "uniqueidentifier",
nullable: false,
defaultValue: Guid.Empty);
// 4️⃣ DocumentImage.IsIT
migrationBuilder.AddColumn<bool>(
name: "IsIT",
schema: "irby",
table: "DocumentImage",
type: "bit",
nullable: false,
defaultValue: false);
// 5️⃣ DocumentCategory.IsIT
migrationBuilder.AddColumn<bool>(
name: "IsIT",
schema: "irby",
table: "DocumentCategory",
type: "bit",
nullable: false,
defaultValue: false);
// 6️⃣ DocumentAttribute.IsIT
migrationBuilder.AddColumn<bool>(
name: "IsIT",
schema: "irby",
table: "DocumentAttribute",
type: "bit",
nullable: false,
defaultValue: false);
}
AddColumn<T>calls define new columns in the specified table & schema.- Default values ensure existing rows get a neutral (
false/000...0) value.
4.2 Down Method
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(name: "IsIT", schema: "irby", table: "TempDocumentData");
migrationBuilder.DropColumn(name: "IsIT", schema: "irby", table: "DocumentType");
migrationBuilder.DropColumn(name: "ITDocumentType", schema: "irby", table: "DocumentImage");
migrationBuilder.DropColumn(name: "IsIT", schema: "irby", table: "DocumentImage");
migrationBuilder.DropColumn(name: "IsIT", schema: "irby", table: "DocumentCategory");
migrationBuilder.DropColumn(name: "IsIT", schema: "irby", table: "DocumentAttribute");
}
- Reverts the
Upchanges by dropping each column in reverse order.
⚙️ Usage & Examples
Applying the Migration
Using the .NET CLI:
# Create the migration (if not auto‑generated):
dotnet ef migrations add ITDMS -c IrbyImagingDbContext
# Apply to the database:
dotnet ef database update -c IrbyImagingDbContext
Using Package Manager Console in Visual Studio:
PM> Add-Migration ITDMS -Context IrbyImagingDbContext
PM> Update-Database -Context IrbyImagingDbContext
⏪ Rollback & Down Migration
To roll back this migration:
# Replace <PreviousMigration> with the name before ITDMS
dotnet ef database update <PreviousMigration> -c IrbyImagingDbContext
or in PMC:
PM> Update-Database <PreviousMigration> -Context IrbyImagingDbContext
🗂️ File Structure & Location
IrbyImaging.DbContext
└── Migrations
├── 20230801120000_InitialCreate.cs
├── ...
└── 20231003133244_ITDMS.cs ← this file
- Namespace:
IrbyImaging.DbContext.Migrations - Part of EF Core’s Migrations sub‑folder.
UML Class Diagram
+--------------------------------------+
| ITDMS : Migration |
+--------------------------------------+
| + Up(mb: MigrationBuilder): void |
| + Down(mb: MigrationBuilder): void |
+--------------------------------------+
| - Adds multiple IsIT columns |
| - Adds ITDocumentType (GUID) |
+--------------------------------------+
❗ API Endpoints & Integrations
N/A
This file is purely a database schema migration. No HTTP controllers, endpoints, or external integrations are defined here.
✅ Conclusion
This migration is a schema extension to enable tracking of IT‑specific documents, categories, and images.
By adding lightweight boolean flags and a GUID link, you can:
- Filter and query only IT‑related records.
- Establish relationships between images and IT document types.
- Seamlessly integrate IT workflows into your existing document management pipeline.
Once applied, update any Entity Models, Repositories, or DTOs to take advantage of these new columns in your business logic and UI layers.
🚀 Happy Coding!