πŸ—‚οΈ Documentation: UpdateLegalDashboardTables.Designer.cs

Path: IrbyImaging.DbContext/Migrations/20240318162041_UpdateLegalDashboardTables.Designer.cs


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
    3.1 Entity & Table Mappings
    3.2 Inheritance & Discriminators
    3.3 Relationships & Navigation
  4. How It Works
    4.1 BuildTargetModel Method
    4.2 Fluent API Configuration
  5. Usage & Examples
  6. UML Class Diagram (Simplified)
  7. Conclusion

πŸ“ Overview & Purpose

This auto-generated .Designer.cs file is part of Entity Framework Core’s migration system. It represents the target model snapshot after applying the UpdateLegalDashboardTables migration.

  • Purpose:
    • Captures table schemas, columns, keys, indexes, inheritance, and relationships.
    • Enables EF Core to compare model changes and generate future migrations.
  • Note:
    • Do not manually edit this file.
    • Use dotnet ef migrations add and dotnet ef database update commands to create/apply migrations.

βš™οΈ Dependencies & Technologies

Technology Version Role
.NET 7.0 7.0.7 Target framework
Entity Framework Core 7.x ORM / Migrations
Microsoft.SqlServer β€” Underlying relational database provider
C# 10+ Programming language

πŸš€ Key Functional Areas

1. Entity & Table Mappings

The BuildTargetModel method configures 100+ domain entities. Each call to modelBuilder.Entity(...) maps a CLR class to a relational table.

Sample Table of Entities

CLR Entity Schema Table Name Primary Key
Asset irby Asset Id : uniqueidentifier
AssetHistory irby AssetHistory Id : uniqueidentifier
DocumentImage irby DocumentImage DocumentImageId
DocumentCategory irby DocumentCategory Id
AuditDetail irby AuditDetail AuditDetailId
Job irby Job JobId
Employee irby Employee EmployeeId
Permissions irby Permissions PermissionId
Role irby Role RoleId
…and many more (ODS, Leasing, TimeSheet, IPMMigration, etc.)

2. Inheritance & Discriminators

Certain tables use Table-Per-Hierarchy (TPH) to model inheritance:

  • Asset
    • Discriminator column: Discriminator
    • Subclasses:
      • Computer (β†’ adds AssetNumber, CpsNumber, OperatingSystemId, UnitNumber)
      • MobileDevice (β†’ adds Carrier, Imei, PhoneNumber, etc.)
      • DeskPhone, Dock, Monitor, NetworkEquipment, OfficePrinter, Printer, SafetyEquipment
    • Configured with .UseTphMappingStrategy() and .HasDiscriminator(...).

3. Relationships & Navigation

  • One-to-Many
    • Asset β†’ AssetHistory
    • Job β†’ Employee
    • FieldOffice β†’ Jobs, Assets
    • Ticket β†’ Updates
  • Many-to-Many (via linking tables)
    • Role ↔ Permissions (LinkRolePermission)
    • Employee ↔ Role (LinkUserRole)
  • Foreign Keys & Cascades
    • Configured with .HasForeignKey(...), .OnDelete(DeleteBehavior.Cascade) when required.
    • Indexes on FKs for performance.

πŸ” How It Works

BuildTargetModel Method

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

    // Enable IDENTITY columns for SQL Server
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // Configure each entity...
    modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
    {
        b.Property<Guid>("Id")
            .ValueGeneratedOnAdd()
            .HasColumnType("uniqueidentifier");
        b.Property<string>("Category")
            .IsRequired()
            .HasColumnType("nvarchar(max)");
        // … other props …
        b.HasKey("Id");
        b.ToTable("Asset", "irby");
        b.HasDiscriminator<string>("Discriminator")
            .HasValue("Asset");
    });

    // … thousands of lines of entity configurations …
    #pragma warning restore 612, 618
}

Fluent API Configuration

  • Properties: .HasColumnType(), .IsRequired(), .ValueGeneratedOnAdd()
  • Keys & Indexes: .HasKey(), .HasIndex(), .IsUnique()
  • Table Mapping: .ToTable("Name", "Schema")
  • Inheritance: .HasDiscriminator(), .UseTphMappingStrategy()
  • Relationships: .HasOne(...).WithMany(...).HasForeignKey(...)

βš™οΈ Usage & Examples

Applying the Migration

# From your project directory
dotnet ef migrations add UpdateLegalDashboardTables
dotnet ef database update 20240318162041_UpdateLegalDashboardTables

Inspecting the Model

You can use EF Core commands to view the model snapshot:

dotnet ef migrations script 20240318162041_UpdateLegalDashboardTables

Code-First Workflow

  1. Modify or add your domain classes and/or DbContext.
  2. Run dotnet ef migrations add <YourMigrationName>.
  3. Review the generated .Designer.cs files (snapshot).
  4. Update database with dotnet ef database update.

🧩 UML Class Diagram (Simplified)

classDiagram
    Asset <|-- Computer
    Asset <|-- MobileDevice
    Asset <|-- DeskPhone
    AssetModel --> Manufacturer : Make
    Asset --> AssetModel : Model
    AssetHistory --> Asset : AssetId
    DocumentImage --> DocumentCategory : DocumentType
    Employee --> Department
    Employee --> Job
    Job --> FieldOffice
    Role "1" <-- "M" LinkUserRole --> Employee "1"
    Role "1" <-- "M" LinkRolePermission --> Permissions "1"
    Ticket --> Update
    TimeSheetEntry --> Employee
    TimeSheetEntry --> TimeEntryType

🏁 Conclusion

This migration snapshot is a comprehensive blueprint of the database schema for the IrbyImaging application after applying the UpdateLegalDashboardTables migration. It:

  • Defines 100+ tables and their columns
  • Configures keys, indexes, and relationships
  • Models inheritance for assets
  • Serves as a reference for EF Core to generate, apply, and revert migrations

πŸŽ‰ With this documentation you have both a conceptual and technical overview of how EF Core maps your domain model to a SQL Server database.