📄 Documentation: 20240131151348_AddPWDColumnsToEmployeeTable.Designer.cs


🗂 Table of Contents

  1. Overview & Purpose
  2. Context: EF Core Migrations
  3. Key Method: BuildTargetModel
  4. Spotlight: Employee Entity & New Columns
  5. Model Snapshot & Entity Mapping
  6. How to Apply This Migration
  7. UML Diagram (Mermaid)
  8. Conclusion

1. Overview & Purpose 📋

This file is an auto‑generated EF Core migration designer class that captures the state of your EF Core model after applying the migration named:

AddPWDColumnsToEmployeeTable
Timestamp: 2024-01-31 15:13:48

  • Role: EF Core uses this snapshot to compute schema differences when you add future migrations.
  • Primary Change: Addition of two new columns—PWReset and PWResetDate—to the Employee table.

2. Context: EF Core Migrations 🔧

[DbContext(typeof(IrbyContext))]
[Migration("20240131151348_AddPWDColumnsToEmployeeTable")]
partial class AddPWDColumnsToEmployeeTable
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        // … entire model snapshot …
    }
}
  • DbContext: IrbyContext
  • MigrationId: "20240131151348_AddPWDColumnsToEmployeeTable"
  • Designer File: Contains only the BuildTargetModel method—no Up/Down scripts here.

When you run:

dotnet ef migrations add AddPWDColumnsToEmployeeTable

EF Core generates two files:

  1. 20240131151348_AddPWDColumnsToEmployeeTable.cs ➞ Contains Up() and Down() methods.
  2. 20240131151348_AddPWDColumnsToEmployeeTable.Designer.cs ➞ This snapshot.

3. Key Method: BuildTargetModel 🚀

  • Purpose: Reconstructs your EF Core model in code so EF can diff it against previous snapshots.
  • Structure:
    1. Global Annotations
      modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);
      SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
      
    2. Entity Definitions
      For each domain class (Asset, Employee, Job, etc.), there is a call:
      modelBuilder.Entity("Namespace.DomainClasses.MyEntity", b => {
          b.Property<...>("PropertyName")...
          b.HasKey("KeyProperty");
          b.ToTable("MyEntity", "schema");
          // indexes, relationships, discriminator (for TPH), etc.
      });
      
    3. Relationships & Navigation
      After all entities are defined, there are .HasOne() and .WithMany() calls to wire up FKs.

4. Spotlight: Employee Entity & New Columns 🔑

Full Mapping Snippet

modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => {
    b.Property<Guid>("EmployeeId")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");

    // … existing columns …

    // 🔥 New columns added by this migration:
    b.Property<bool>("PWReset")
     .HasColumnType("bit");

    b.Property<DateTime>("PWResetDate")
     .HasColumnType("datetime2");

    // … rest of mapping …

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

💡 Summary of New Columns

Column CLR Type SQL Type Nullable Default Value Description
PWReset bool bit NO false Indicates if the employee needs a reset.
PWResetDate DateTime datetime2 NO 0001-01-01 Timestamp when reset was triggered.

Note: In your Up() method (not shown here), EF will typically scaffold:

migrationBuilder.AddColumn<bool>(
    name: "PWReset",
    schema: "irby",
    table: "Employee",
    nullable: false,
    defaultValue: false);

migrationBuilder.AddColumn<DateTime>(
    name: "PWResetDate",
    schema: "irby",
    table: "Employee",
    nullable: false,
    defaultValue: new DateTime(yyyy, mm, dd, …));

5. Model Snapshot & Entity Mapping 🗺️

Beyond Employee, this file records the entire domain model, including:

  • Asset Hierarchy (TPH):
    Asset (base) → Computer, DeskPhone, MobileDevice, ...
  • Reference Entities:
    Department, Role, Permissions, FieldOffice, Job, Customer, GeneralLedger, etc.
  • Many-to-many / Linking:
    LinkUserRole, LinkRolePermission
  • Lookup / Reporting Views:
    AuditReport, LicenseReport, DirectorLeaseInfo, etc.
  • External Sync Tables:
    ODSCustomer, ODSEmployee, ODSJob

Each entity block includes:

  • Column definitions with types & nullability
  • Primary keys via .HasKey()
  • Indexes via .HasIndex()
  • Schema and table name via .ToTable("Name","schema")
  • Inheritance (TPH) with .HasDiscriminator()

6. How to Apply This Migration 🛠️

  1. Add the migration (already done):
    dotnet ef migrations add AddPWDColumnsToEmployeeTable
    
  2. Review the generated .cs Up/Down script.
  3. Update the database:
    dotnet ef database update
    
  4. Verify in SQL Server that irby.Employee has the two new columns:
    EXEC sp_help 'irby.Employee';
    

7. UML Diagram (Mermaid) 📈

classDiagram
  class Employee {
    +Guid EmployeeId
    +string FirstName
    +string LastName
    +string JdeNumber
    +bool PWReset           <<new>>
    +DateTime PWResetDate   <<new>>
    +...                    // other properties
  }
  Employee --> Department : FK DepartmentId
  Employee --> Job        : FK JobId
  Employee --> Role       : FK RoleId

8. Conclusion 🎉

  • This Designer file is an EF Core internal snapshot reflecting your complete domain model after adding the password‑reset columns.
  • It underpins subsequent migrations by providing a baseline for model‑to‑database diffs.
  • You should normally not modify it by hand—treat it as a read‑only artifact generated by the EF tooling.

Happy coding! 🛡️🚀