IrbyImaging.DbContext/Migrations/20230711133845_updateAddIsHRColumn.cs Documentation πŸ“‘


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies πŸ› οΈ
  3. Key Functional Areas πŸ”‘
  4. Migration Class Details πŸ”
  5. Data Models & Impact on Entities πŸ—„οΈ
  6. Usage Examples & Commands πŸš€
  7. UML Diagram πŸ“Š
  8. 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 β†’ IsHR
  • HrDocumentType β†’ 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:
    • RenameColumn for IsHr β†’ IsHR.
    • RenameColumn for HrDocumentType β†’ HRDocumentType.

4.2 Down Method

  • Purpose: Revert the changes if the migration is rolled back.
  • Operations:
    • RenameColumn for IsHR β†’ IsHr.
    • RenameColumn for HRDocumentType β†’ 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 πŸš€

  1. Add Migration

    dotnet ef migrations add updateAddIsHRColumn \
        --context IrbyImagingContext \
        --output-dir IrbyImaging.DbContext/Migrations
    
  2. Apply Migration

    dotnet ef database update --context IrbyImagingContext
    
  3. 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 DocumentImage table.
  • Next Steps:
    1. Update your C# models to match the new names.
    2. Rebuild and run your application to ensure no mismatches in LINQ/queries.
    3. Run integration tests that touch the DocumentImage entity to confirm correct behavior.

Thank you for using Entity Framework Core Migrations to keep your schema clean and consistent! πŸŽ‰