πŸ“¦ Migration Designer: AddUARApproverToEmployeeTable

πŸ—‚ Table of Contents

  1. Overview & Purpose
  2. Migration Context
  3. Key Model Change
  4. BuildTargetModel Method
  5. Entity Configuration Highlights
  6. Dependencies & Technologies
  7. Usage & Examples
  8. UML Class Diagram
  9. Developer Considerations & Best Practices
  10. Conclusion

1. πŸ” Overview & Purpose

File:

IrbyImaging.DbContext/Migrations/
    20230718150337_AddUARApproverToEmployeeTable.Designer.cs

This is an auto-generated EF Core migration snapshot. It represents the state of your entity model after applying the migration named AddUARApproverToEmployeeTable.

Why does it exist?

  • EF Core needs a β€œmodel snapshot” to compare the current model vs. previous snapshots.
  • The .Designer.cs file stores all tables, columns, indexes, relationships, and annotations.
  • It is used by EF Core tools to generate SQL scripts for schema changes.

⚠️ Do NOT manually edit this file!
Always modify your domain classes and run dotnet ef migrations add <Name>.


2. πŸ—Ί Migration Context

Property Value
Migration ID 20230718150337_AddUARApproverToEmployeeTable
DbContext IrbyContext
Target Add column UARApprover to Employee table
Schema irby
Provider Microsoft SQL Server

This migration’s sole purpose is to add a new boolean property to the Employee entity, which will reflect in the Employee table as a column of type bit.


3. ✨ Key Model Change

Entity Property CLR Type SQL Column SQL Type Default
Employee UARApprover bool UARApprover bit 0 (false)

πŸ“ Code Snippet: New Property Mapping

modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
    // ... existing properties ...

    b.Property<bool>("UARApprover")       // πŸ”₯ New boolean column
     .HasColumnType("bit");
    
    // ... keys, indexes, relationships ...
});

4. πŸ— BuildTargetModel Method

The core of this snapshot is the BuildTargetModel override:

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    // Use Identity columns for SQL Server:
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // Define each entity in the model...
    modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
    {
        b.Property<Guid>("EmployeeId")
         .ValueGeneratedOnAdd()
         .HasColumnType("uniqueidentifier");

        // ... other existing properties ...

        b.Property<bool>("UARApprover")         // Newly added
         .HasColumnType("bit");

        b.HasKey("EmployeeId");

        b.HasIndex("JdeNumber")
         .IsUnique()
         .HasFilter("[JdeNumber] IS NOT NULL");

        b.ToTable("Employee", "irby");
        // ... relationships ...
    });

    // ... definitions for dozens of other entities ...
}

Responsibilities of BuildTargetModel:

  • Apply global annotations (e.g., EF Core version, SQL Server conventions)
  • Configure identity columns
  • Map every entity β†’ table, columns, keys, indexes
  • Set up relationships and navigation properties

5. πŸ“Š Entity Configuration Highlights

While this snapshot contains many entities, here are the most relevant for this migration:

Employee Entity

Property CLR Type SQL Type Notes
EmployeeId Guid uniqueidentifier Primary Key, ValueGeneratedOnAdd
FirstName string nvarchar(max)
LastName string nvarchar(max)
JdeNumber string nvarchar(450) Unique Index, Nullable
Status string nvarchar(max) Required
UARApprover bool bit New

Table Mapping:

b.ToTable("Employee", "irby");

Relationship Sample

modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.Department", "Department")
     .WithMany()
     .HasForeignKey("DepartmentId");
});
  • Employee β†’ Department (Many-to-One)
  • FK: DepartmentId

6. πŸ› οΈ Dependencies & Technologies

  • .NET 7.0
  • Entity Framework Core 7.0.7
  • SQL Server provider
  • Uses DateTimeOffset, decimal, varbinary(max)

7. πŸ“˜ Usage & Examples

1. Add the Migration

dotnet ef migrations add AddUARApproverToEmployeeTable

2. Update the Database

dotnet ef database update

3. Inspect Generated SQL

dotnet ef migrations script 20230718150337_AddUARApproverToEmployeeTable

You’ll see SQL akin to:

ALTER TABLE [irby].[Employee]
ADD [UARApprover] bit NOT NULL DEFAULT 0;

8. πŸ“ UML Class Diagram

classDiagram
    class Employee {
      <<Entity>>
      +Guid EmployeeId
      +string FirstName
      +string LastName
      +string JdeNumber
      +string Status
      +bool UARApprover
    }
    class Department {
      <<Entity>>
      +Guid DepartmentId
      +string Name
    }
    Employee --> Department : DepartmentId

9. πŸ€” Developer Considerations & Best Practices

  • Do NOT hand-edit .Designer.cs snapshots.
  • Always update your domain classes, then run Add-Migration.
  • Review migrations before applying in production.
  • Use a staging environment to verify schema changes.
  • Keep naming conventions consistent to avoid long rebasing.

10. βœ… Conclusion

This Designer snapshot captures the complete model after adding the UARApprover flag to Employee. EF Core uses this to:

  • Track schema changes
  • Generate database update scripts
  • Maintain a history of migrations

By following EF Core migration patterns, you ensure a consistent, versioned, and reliable database schema that matches your C# domain model.

πŸš€ Happy coding and smooth deployments!