πŸ—‚ Migration Documentation:

AddNewColumnsEmployeeAndAuditTable.Designer.cs
IrbyImaging.DbContext/Migrations/20230828165122_AddNewColumnsEmployeeAndAuditTable.Designer.cs


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Models Overview
  5. Sample Code Snippets
  6. UML Diagram (Asset Hierarchy)
  7. Usage & Applying the Migration
  8. Conclusion

1. Overview & Purpose

This file is an auto-generated designer class for the Entity Framework Core migration AddNewColumnsEmployeeAndAuditTable.

  • πŸ— Role: Keeps a snapshot of the EF Core model after the migration is applied.
  • πŸ”„ When It Runs: During dotnet ef migrations add and update-database.
  • 🎯 Why It Exists: EF Core uses it to compare your C# model against the database schema, scaffold future migrations, and apply changes reliably.

2. Dependencies & Technologies

Technology / Package Version / Notes
Microsoft.EntityFrameworkCore 7.0.7
Microsoft.EntityFrameworkCore.SqlServer Underlying relational provider
.NET 7.0 Target framework
C# / Nullable Disabled #nullable disable at top of file

3. Key Functional Areas

3.1 BuildTargetModel Method

[DbContext(typeof(IrbyContext))]
[Migration("20230828165122_AddNewColumnsEmployeeAndAuditTable")]
partial class AddNewColumnsEmployeeAndAuditTable
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        modelBuilder
            .HasAnnotation("ProductVersion", "7.0.7")
            .HasAnnotation("Relational:MaxIdentifierLength", 128);

        SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
        // ... entity configurations follow ...
    }
}
  • BuildTargetModel: Core method where all entities, their properties, keys, indexes, relationships, and table mappings are defined.
  • Annotations:
    • "ProductVersion" locks the EF Core version.
    • "Relational:MaxIdentifierLength" for SQL Server limits.
  • UseIdentityColumns: Enables SQL Server identity (auto‑increment) on key properties by convention.

3.2 Entity Mappings

  • Each call to modelBuilder.Entity("Namespace.ClassName", b => { … }) configures a table.
  • Table & Schema:
    • e.g. b.ToTable("Employee", "irby"); maps the Employee entity to irby.Employee.
  • Property Configuration:
    • .HasColumnType("uniqueidentifier") β†’ Guid on SQL Server.
    • .IsRequired() β†’ NOT NULL.
    • .ValueGeneratedOnAdd() β†’ IDENTITY or computed by database on INSERT.

3.3 Relationships & Foreign Keys

  • Defined at the bottom via .HasOne(…) / .WithMany(…).
  • Example:
    modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => {
        b.HasOne("IrbyImaging.DomainClasses.Department", "Department")
         .WithMany()
         .HasForeignKey("DepartmentId");
    });
    
  • Cascade Deletes:
    • .OnDelete(DeleteBehavior.Cascade) ensures child rows are removed when parent is deleted.

3.4 Indexes & Constraints

  • Primary Key:
    b.HasKey("EmployeeId");
    
  • Unique Index:
    b.HasIndex("JdeNumber")
      .IsUnique()
      .HasFilter("[JdeNumber] IS NOT NULL");
    
  • Standard Index:
    b.HasIndex("RoleId");
    

3.5 Inheritance & TPH Mapping

  • Table-Per-Hierarchy (TPH) for Asset and sub‑types (Computer, MobileDevice, etc.).
  • Discriminator Column:
    modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
        b.HasDiscriminator<string>("Discriminator")
         .HasValue("Asset");
        b.UseTphMappingStrategy();
    });
    
  • Subclasses override .HasDiscriminator().HasValue("SubTypeName").

4. Data Models Overview

Below is a subset of the dozens of domain entities configured by this migration.

Entity Name Table Name Schema Key Property Notes
Asset Asset irby Id (uniqueidentifier) Base class for many assets.
Employee Employee irby EmployeeId (Guid) Has indexes on JdeNumber, Dept, Role.
AuditDetail AuditDetail irby AuditDetailId (Guid) New audit trail table.
CarrierTypeDetail CarrierTypeDetail irby Id (Guid) FK β†’ CarrierType.
TimeSheetEntry TimeSheetEntry irby TimeSheetEntryId FK β†’ Employee, TimeEntryType.
… … … … …

Tip: This migration adds new columns and new tables for Employee and Audit tracking, reflected here in the expanded model snapshot.


5. Sample Code Snippets

Mapping a Simple Entity

modelBuilder.Entity("IrbyImaging.DomainClasses.Department", b =>
{
    b.Property<Guid>("DepartmentId")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");
    b.Property<string>("Name")
     .HasColumnType("nvarchar(max)");
    b.HasKey("DepartmentId");
    b.ToTable("Department", "irby");
});

Defining a Foreign Key Relationship

modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.Employee", "Owner")
     .WithMany("Assets")
     .HasForeignKey("OwnerId");
});

6. UML Diagram (Asset Hierarchy)

Below is a simplified PlantUML snippet illustrating the Asset inheritance:

@startuml
abstract class Asset {
  +Guid Id
  +string Category
  +DateTimeOffset PurchaseDate
}

class Computer extends Asset {
  +string AssetNumber
  +int OperatingSystemId
}

class MobileDevice extends Asset {
  +string Imei
  +bool IsTelogis
}

Asset <|-- Computer
Asset <|-- MobileDevice
@enduml

Asset TPH Diagram


7. Usage & Applying the Migration

  1. Add Migration
    dotnet ef migrations add AddNewColumnsEmployeeAndAuditTable
    
  2. Update Database
    dotnet ef database update
    
  3. Review Generated SQL
    • Inspect the corresponding *.sql to see DDL for new columns/tables.

πŸš€ After applying, your database schema will match the model snapshot defined herein.


8. Conclusion

This designer file is a model snapshot that ensures EF Core can:

  • Track your domain model structure.
  • Scaffold future migrations accurately.
  • Reconstruct the model when updating or rolling back.

Note: You typically do not edit this file manually. Changes in your C# domain classes β†’ dotnet ef migrations add β†’ this file will be regenerated.


✨ Happy Coding!
This documentation should serve as a reference for understanding how EF Core has configured your model and how the new Employee & Audit tables are integrated.