πŸ“‘ Documentation: 20240201193312_UpdateEmployeeTableWithNewColumns4.Designer.cs

File Path:
IrbyImaging.DbContext/Migrations/20240201193312_UpdateEmployeeTableWithNewColumns4.Designer.cs


πŸ“– Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Migration Configuration
  4. πŸ” Data Models (Entities)
  5. πŸ”— Relationships & Constraints
  6. πŸ”€ Inheritance & TPH Strategy
  7. πŸš€ Usage & Integration
  8. πŸ“œ Sample Commands
  9. πŸ“Š UML Diagram (Mermaid)
  10. πŸ“ Conclusion

πŸ“– Overview & Purpose

This Designer file is an auto-generated snapshot of your Entity Framework Core model after applying the migration named UpdateEmployeeTableWithNewColumns4. It is used internally by EF Core to:

  • Reconstruct the target database schema (tables, columns, keys, relationships).
  • Compare model snapshots during migrations apply or rollback.
  • Drive the SQL generation that brings your database in sync with your C# model.

⚠️ Note: You normally should not edit this file by hand.
Changes are pushed here automatically each time you add a new migration.


πŸ› οΈ Dependencies & Technologies

Technology / Package Version Purpose
.NET SDK 7.0.7 Runtime & compilation target
EntityFrameworkCore 7.0.* ORM mapping & migrations
Microsoft.EntityFrameworkCore.SqlServer 7.0.* SQL Server provider
C# 11 Language
SQL Server 2019+ Database

Additional EF Core namespaces imported:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

πŸ”§ Migration Configuration

Attributes & Metadata

[DbContext(typeof(IrbyContext))]
[Migration("20240201193312_UpdateEmployeeTableWithNewColumns4")]
partial class UpdateEmployeeTableWithNewColumns4 : Migration
{
    // ...
}
  • [DbContext] links the migration to your IrbyContext.
  • [Migration] attribute carries the timestamped name that EF uses for ordering.

BuildTargetModel Method

At the core of this file is the override:

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    #pragma warning disable 612, 618
    modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // β†’ Configuration for dozens of entities…
    modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
    {
        b.Property<Guid>("EmployeeId")
            .ValueGeneratedOnAdd()
            .HasColumnType("uniqueidentifier");

        // … many properties …

        b.HasKey("EmployeeId");
        b.HasIndex("JdeNumber")
            .IsUnique()
            .HasFilter("[JdeNumber] IS NOT NULL");
        b.ToTable("Employee", "irby");
    });

    // … additional Entity configurations …

    #pragma warning restore 612, 618
}

Responsibilities:

  • Defines global annotations (provider version, identifier length).
  • Registers identity column strategy for SQL Server.
  • Iterates through all entities, specifying:
    • Properties (type, IsRequired, conversions).
    • Keys & Indexes.
    • Table mappings & schema.
    • Discriminators for inheritance (TPH).

πŸ” Data Models (Entities)

This snapshot includes 70+ entity configurations. Below we focus on the Employee entity and a few other highlights.

Key Entity: Employee

Column CLR Type SQL Type Required Notes
EmployeeId Guid uniqueidentifier Yes Primary Key, identity-style
AzureUserId Guid uniqueidentifier No
FirstName string nvarchar(max) No
LastName string nvarchar(max) No
JdeNumber string nvarchar(450) No Unique index if not NULL
Email string nvarchar(max) No
EmploymentStartDate DateTime? datetime2 No
Status string nvarchar(max) Yes
JobId Guid uniqueidentifier Yes FK β†’ Job
DepartmentId Guid? uniqueidentifier No FK β†’ Department
RoleId Guid? uniqueidentifier No FK β†’ Role

πŸ”‘ Primary Key: EmployeeId
πŸ”Ž Indexes:

  • Unique on JdeNumber ([JdeNumber] IS NOT NULL)
  • Foreign keys: JobId, DepartmentId, RoleId

Selected Entity Configurations

Entity Table Schema Notes
IrbyImaging.DomainClasses.Job Job irby Unique index on JdeNumber
IrbyImaging.DomainClasses.Asset Asset irby TPH root, Discriminator column
IrbyImaging.DomainClasses.Department Department irby Soft-delete flag IsDeleted
IrbyImaging.DomainClasses.Role Role irby Many-to-many via LinkUserRole
IrbyImaging.DomainClasses.AssetModel AssetModel irby FK β†’ AssetManufacturer
… and many more…

πŸ”— Relationships & Constraints

  • One-to-Many
    • Employee β†’ Job (JobId)
    • Department β†’ Employees
    • Role β†’ LinkUserRole β†’ Employee
  • Many-to-Many
    • Role ↔ Permissions via LinkRolePermission
    • Employee ↔ Role via LinkUserRole
  • Cascade Deletes
    • Removing a Job cascades to related Employees.
    • Removing a Role cascades to its Permissions links.
  • Indexes
    • Unique: Employee(JdeNumber), Job(JdeNumber), FieldOffice(JdeNumber), MobileDevice(Imei)
    • Filters ensure NULLable columns do not break uniqueness.

πŸ”€ Inheritance & TPH Strategy

The Asset entity uses a Table‑per‑Hierarchy approach:

  • Discriminator column (string) distinguishes subtypes:
    • Computer
    • MobileDevice
    • DeskPhone
    • Dock
    • Monitor
    • OfficePrinter
    • Printer
    • NetworkEquipment
    • SafetyEquipment
  • All subtypes share the Asset table.
  • EF Core’s UseTphMappingStrategy() is invoked by default.

πŸš€ Usage & Integration

  1. Adding a Migration:

    dotnet ef migrations add UpdateEmployeeTableWithNewColumns4 \
        --context IrbyContext
    
  2. Applying to Database:

    dotnet ef database update \
        --context IrbyContext
    
  3. Reviewing SQL Script:

    dotnet ef migrations script 20240201193312_UpdateEmployeeTableWithNewColumns4
    

The Designer file will be updated automatically whenever you scaffold a new migration.


πŸ“œ Sample Commands

# Scaffold a new migration based on model changes
dotnet ef migrations add UpdateEmployeeTableWithNewColumns4

# Apply pending migrations to the DB
dotnet ef database update

# Generate full migration SQL for review
dotnet ef migrations script

πŸ“Š UML Diagram (Mermaid)

classDiagram
    class Employee {
      +Guid EmployeeId
      +string FirstName
      +string LastName
      +string JdeNumber
      +string Status
    }
    class Department {
      +Guid DepartmentId
      +string Name
    }
    class Job {
      +Guid JobId
      +string Name
      +string JdeNumber
    }
    class Role {
      +Guid RoleId
      +string Name
    }
    Employee --> Department : DepartmentId
    Employee --> Job        : JobId
    Employee --> Role       : RoleId

πŸ“ Conclusion

This Designer snapshot is the backbone of your EF Core migration UpdateEmployeeTableWithNewColumns4. It captures the complete state of your modelβ€”entities, properties, indexes, relationships, inheritance strategiesβ€”so EF can generate and validate your database schema.

πŸ”§ Tip: Keep your domain classes and migrations in sync. Always let EF Core manage these Designer files to ensure smooth upgrades and rollbacks.


Happy coding! πŸš€βœ¨