πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Migration File Structure
  4. Key Functional Areas
  5. Data Model Impact
  6. Usage Examples
  7. UML Class Diagram
  8. Conclusion

πŸ” 1. Overview & Purpose

The 20240201184940_UpdateEmployeeTableWithNewColumns3 migration is part of the Entity Framework Core code-first approach. Its primary goal is to add a new FieldOfficeId column (of type GUID) to the JobAndFieldOfficeMapping table, enabling stronger referential integrity by linking jobs to a specific field office.

Why this Migration?

  • Ensure each job-office mapping includes a FieldOfficeId.
  • Support new business logic around multi-office assignments.
  • Prepare the schema for future foreign‑key relationships or lookups.

πŸ› οΈ 2. Dependencies & Technologies

Technology Version / Details
.NET SDK 6.x, 7.x (or higher)
Entity Framework Core Microsoft.EntityFrameworkCore (EF Core)
C# 10+

Note: Migrations are generated via the dotnet ef CLI or Package Manager Console (PMC).


πŸ“ 3. Migration File Structure

IrbyImaging.DbContext
└─ Migrations
   └─ 20240201184940_UpdateEmployeeTableWithNewColumns3.cs

Namespace:

namespace IrbyImaging.DbContext.Migrations

Class Signature:

public partial class UpdateEmployeeTableWithNewColumns3 : Migration

This class inherits from Microsoft.EntityFrameworkCore.Migrations.Migration.


πŸš€ 4. Key Functional Areas

4.1 Up Method

  • Purpose: Define the changes to apply when the migration runs (Update-Database or dotnet ef database update).
  • Action: Adds a non-nullable GUID column named FieldOfficeId to the JobAndFieldOfficeMapping table, with a default value of 00000000-0000-0000-0000-000000000000.
protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.AddColumn<Guid>(
        name: "FieldOfficeId",
        table: "JobAndFieldOfficeMapping",
        type: "uniqueidentifier",
        nullable: false,
        defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
}
Parameter Description
name "FieldOfficeId" – Column name
table "JobAndFieldOfficeMapping" – Target table
type "uniqueidentifier" – SQL Server GUID type
nullable false – Column cannot be null
defaultValue Guid.Empty – Prevents issues on existing rows

4.2 Down Method

  • Purpose: Revert the schema changes when rolling back the migration (dotnet ef database update <PreviousMigration>).
  • Action: Drops the FieldOfficeId column from JobAndFieldOfficeMapping.
protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.DropColumn(
        name: "FieldOfficeId",
        table: "JobAndFieldOfficeMapping");
}

πŸ—‚οΈ 5. Data Model Impact

While this file itself does not define the entity class, it affects the underlying model:

public class JobAndFieldOfficeMapping
{
    public Guid Id { get; set; }
    public Guid JobId { get; set; }
    public Guid FieldOfficeId { get; set; } // ← New property to map to DB column
    // ... other properties ...
}

After applying the migration, ensure your DbContext and entity classes include the new FieldOfficeId property.


βš™οΈ 6. Usage Examples

6.1 Generating the Migration

dotnet ef migrations add UpdateEmployeeTableWithNewColumns3 \
    --project IrbyImaging.DbContext \
    --startup-project IrbyImaging.Api

6.2 Applying & Rolling Back

  • Apply migration:
    dotnet ef database update
    
  • Rollback to previous migration:
    dotnet ef database update 20240115094722_PreviousMigrationName
    

πŸ“ 7. UML Class Diagram

@startuml
class Migration {
  +Up(migrationBuilder)
  +Down(migrationBuilder)
}
class UpdateEmployeeTableWithNewColumns3 {
  +Up(migrationBuilder)
  +Down(migrationBuilder)
}
Migration <|-- UpdateEmployeeTableWithNewColumns3
@enduml

Above: A simple class diagram showing inheritance.


βœ… 8. Conclusion

  • What we did: Added a non-nullable FieldOfficeId GUID column to the JobAndFieldOfficeMapping table.
  • Why it matters: Strengthens the data model, enabling explicit linkages between jobs and field offices.
  • Next steps:
    1. Update your Entity Classes and DbContext to include FieldOfficeId.
    2. Recompile and run integration tests.
    3. Publish the updated database schema in staging/production.

πŸŽ‰ Now your database is ready to handle field‑office assignments more robustly!