IrbyImaging.DbContext/Migrations/20230711133845_updateAddIsHRColumn.cs Documentation π
Table of Contents
- Overview & Purpose
- Dependencies & Technologies π οΈ
- Key Functional Areas π
- Migration Class Details π
- Data Models & Impact on Entities ποΈ
- Usage Examples & Commands π
- UML Diagram π
- Conclusion π
1. Overview & Purpose
File:
IrbyImaging.DbContext/Migrations/20230711133845_updateAddIsHRColumn.cs
This Entity Framework Core Migration class renames two columns in the DocumentImage table in the irby schema:
IsHrβIsHRHrDocumentTypeβHRDocumentType
Why?
To adhere to consistent naming conventions (capitalizing acronyms) and improve readability of the database schema.
2. Dependencies & Technologies π οΈ
| Technology | Version / Notes |
|---|---|
| .NET (Core / 6+) | Modern .NET runtime |
| Entity Framework Core (EF) | Microsoft.EntityFrameworkCore.Migrations |
| Database | SQL Server / any EF Coreβcompatible DB |
| EF Tools (CLI / Package) | dotnet ef migrations / update-database |
3. Key Functional Areas π
3.1 Schema Changes
Affected Schema: irby
Affected Table: DocumentImage
| Old Column Name | New Column Name | Data Type* | Description |
|---|---|---|---|
| IsHr | IsHR | bit |
Flag indicating HR image |
| HrDocumentType | HRDocumentType | nvarchar |
Category/type of HR document |
*Data types inferred from context (boolean and string).
3.2 Migration Class Structure
- Class Name:
updateAddIsHRColumn - Base Class:
Migration - Methods:
Up(MigrationBuilder migrationBuilder)Down(MigrationBuilder migrationBuilder)
4. Migration Class Details π
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IrbyImaging.DbContext.Migrations
{
/// <inheritdoc />
public partial class updateAddIsHRColumn : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "IsHr",
schema: "irby",
table: "DocumentImage",
newName: "IsHR");
migrationBuilder.RenameColumn(
name: "HrDocumentType",
schema: "irby",
table: "DocumentImage",
newName: "HRDocumentType");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "IsHR",
schema: "irby",
table: "DocumentImage",
newName: "IsHr");
migrationBuilder.RenameColumn(
name: "HRDocumentType",
schema: "irby",
table: "DocumentImage",
newName: "HrDocumentType");
}
}
}
4.1 Up Method
- Purpose: Apply the schema changes to the database.
- Operations:
RenameColumnforIsHrβIsHR.RenameColumnforHrDocumentTypeβHRDocumentType.
4.2 Down Method
- Purpose: Revert the changes if the migration is rolled back.
- Operations:
RenameColumnforIsHRβIsHr.RenameColumnforHRDocumentTypeβHrDocumentType.
5. Data Models & Impact on Entities ποΈ
Entity:
DocumentImage(in your DbContext)
public class DocumentImage
{
public int Id { get; set; }
public bool IsHR { get; set; } // Renamed from IsHr
public string HRDocumentType { get; set; } // Renamed from HrDocumentType
// ... other properties ...
}
Impact:
- Update your C# entity to match the renamed columns.
- Mismatch between property names and column names can be resolved via Data Annotations or Fluent API.
6. Usage Examples & Commands π
-
Add Migration
dotnet ef migrations add updateAddIsHRColumn \ --context IrbyImagingContext \ --output-dir IrbyImaging.DbContext/Migrations -
Apply Migration
dotnet ef database update --context IrbyImagingContext -
Roll Back
dotnet ef database update LastGoodMigrationName
π Tip: Always review the generated SQL in your development environment before applying to production.
7. UML Diagram π
classDiagram
class Migration {
<<abstract>>
+Up(MigrationBuilder)
+Down(MigrationBuilder)
}
class updateAddIsHRColumn {
<<Migration>>
+Up(MigrationBuilder)
+Down(MigrationBuilder)
}
Migration <|-- updateAddIsHRColumn
8. Conclusion π
- Purpose Achieved! The migration standardizes the naming of HR-related columns in the
DocumentImagetable. - Next Steps:
- Update your C# models to match the new names.
- Rebuild and run your application to ensure no mismatches in LINQ/queries.
- Run integration tests that touch the
DocumentImageentity to confirm correct behavior.
Thank you for using Entity Framework Core Migrations to keep your schema clean and consistent! π