📄 UpdateFieldOfficeTableWithNewColumns.Designer.cs Documentation


Table of Contents 📑

  1. Index
  2. Overview & Purpose
  3. Dependencies & Technologies
  4. Key Functional Areas
  5. Data Model Highlights
  6. Usage & Workflow 🚀
  7. Mermaid UML Class Diagram 🗺️
  8. Conclusion 🎯

Index

  • File Path
    IrbyImaging.DbContext/Migrations/20240201134411_UpdateFieldOfficeTableWithNewColumns.Designer.cs
  • Class
    partial class UpdateFieldOfficeTableWithNewColumns
  • Namespace
    IrbyImaging.DbContext.Migrations

Overview & Purpose

This auto-generated C# file is part of Entity Framework Core’s migration system. It represents the model snapshot after applying the migration named:

20240201134411_UpdateFieldOfficeTableWithNewColumns

Its main responsibilities are:

  • Reconstruct the entire EF Core data model in code (tables, columns, keys, indexes, relationships).
  • Serve as a point of comparison for EF Core to generate SQL scripts for upgrading or downgrading your database.
  • Provide the ‘design-time’ blueprint so that commands like dotnet ef database update know exactly what schema to expect.

Note: You typically do not edit this file manually—changes come from EF Core’s CLI or Visual Studio tools.


Dependencies & Technologies

Dependency Version Purpose
Microsoft.EntityFrameworkCore 7.0.7 Core Object–Relational Mapper (ORM)
Microsoft.EntityFrameworkCore.SqlServer 7.0.7 SQL Server provider for EF Core
Microsoft.EntityFrameworkCore.Design 7.0.7 Design‑time utilities (migrations, scaffolding)
.NET 7.x Target framework
C# 11 — Language features

Key Functional Areas

Migration Metadata

[DbContext(typeof(IrbyContext))]
[Migration("20240201134411_UpdateFieldOfficeTableWithNewColumns")]
partial class UpdateFieldOfficeTableWithNewColumns
{ … }
  • DbContext attribute links this migration to your IrbyContext.
  • Migration attribute carries the timestamp + descriptive name—ensuring ordering.

BuildTargetModel Method

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    // Suppress warnings about obsolete items
    #pragma warning disable 612, 618

    modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

    // … entity definitions follow …
}
  • Purpose: Reconstruct the EF Core model for all entities.
  • Flow:
    1. Global annotations (EF Core version, identifier length).
    2. Identity column strategy for SQL Server.
    3. Iterate through each entity with modelBuilder.Entity("FullTypeName", b => { … }).

Entity Configuration

For each entity, EF Core’s fluent‑API is used:

  1. Properties

    b.Property<Guid>("Id")
      .ValueGeneratedOnAdd()
      .HasColumnType("uniqueidentifier");
    
    • Defines CLR → column mapping, nullability, data type, identity behavior.
  2. Keys & Indexes

    b.HasKey("Id");
    b.HasIndex("FieldOfficeId");
    b.HasIndex("JdeNumber").IsUnique().HasFilter("[JdeNumber] IS NOT NULL");
    
  3. Table Mapping

    b.ToTable("FieldOffice", "irby");
    
  4. Inheritance / TPH Mapping

    b.HasDiscriminator<string>("Discriminator")
      .HasValue("Asset");
    b.UseTphMappingStrategy();
    

Data Model Highlights

FieldOffice Entity 🏢

This migration primarily updates the FieldOffice table by (re)defining its columns:

Column SQL Type Nullable Description
Id uniqueidentifier No Primary key, GUID identity
AsstProjectManagerId uniqueidentifier Yes FK → Employee
BusinessUnitName nvarchar(max) Yes Branch business unit name
BusinessUnitNumber nvarchar(max) Yes Unit number (string)
DirectorId uniqueidentifier Yes FK → Employee
FaxNumber nvarchar(max) Yes Fax
JdeNumber nvarchar(450) Yes Unique branch code (indexed unique)
LeadId uniqueidentifier Yes FK → Employee
MailingAddress nvarchar(max) Yes Mailing address
ManagerId uniqueidentifier Yes FK → Employee
Name nvarchar(max) Yes Office name
OfficeExtension nvarchar(max) Yes Phone extension
OfficePhone nvarchar(max) Yes Main phone
PrimaryContactId uniqueidentifier Yes FK → Employee
PrimaryContactPhone nvarchar(max) Yes Contact phone
ProjectManagerId uniqueidentifier Yes FK → Employee
ProjectManagerPhone nvarchar(max) Yes Project manager’s phone
SecondaryContactId uniqueidentifier Yes FK → Employee
SecondaryContactPhone nvarchar(max) Yes Secondary contact phone
ShippingAddress nvarchar(max) Yes Shipping address
SuperintendentId uniqueidentifier Yes FK → Employee
SuperintendentPhone nvarchar(max) Yes Superintendent’s phone
  • Relationships:
    Each *Id column points to Employee.EmployeeId, configured with foreign‑key constraints and indexes for fast joins.

Asset Hierarchy & TPH Mapping 💼

  • Base Entity: IrbyImaging.DomainClasses.Asset
  • Discriminator Column: "Discriminator"
  • Derived Types:
    • Computer, DeskPhone, Dock, MobileDevice, Monitor, NetworkEquipment, OfficePrinter, Printer, SafetyEquipment

Key Highlights:

  • Single table (irby.Asset) holds all subtypes → Table‑per‑Hierarchy (TPH).
  • Each subtype adds properties (e.g., Computer adds OperatingSystemId, AssetNumber, etc.)
  • EF Core fluent‑API uses:
    b.HasDiscriminator().HasValue("Computer");
    

Summary of Other Domain Entities 📋

Entity Table (Schema) Key Purpose
AssetHistory irby.AssetHistory Id (Guid) Tracks every change to an asset
AssetModel irby.AssetModel Id (int) Catalog of asset models
AuditDetail irby.AuditDetail AuditDetailId (Guid) Detailed user activity logs
BillingInvoice irby.BillingInvoice Id (Guid) Invoices and billing records
BlobData irby.BlobData BlobDataId (Guid) Temporary storage for document blobs
Customer irby.Customer Id (Guid) Core customer lookup
Department irby.Department DepartmentId (Guid) HR department list
Job irby.Job JobId (Guid) Project/job master data
LinkUserRole irby.LinkUserRole Id (Guid) Junction table for employees ↔ roles
Permission irby.Permissions PermissionId (Guid) Permission catalog
Role irby.Role RoleId (Guid) Role catalog
… and many more

Tip: Inspect the full list in BuildTargetModel—each call to modelBuilder.Entity(...) maps one entity.


Usage & Workflow 🚀

  1. Create or Update Migration
    dotnet ef migrations add UpdateFieldOfficeTableWithNewColumns
    
  2. Review
    • Inspect the generated .cs (Up/Down methods) & Designer.cs to confirm schema changes.
  3. Apply to Database
    dotnet ef database update
    
  4. Rollback (if needed)
    dotnet ef database update PreviousMigrationName
    

Mermaid UML Class Diagram 🗺️

classDiagram
    class FieldOffice {
      +Guid Id
      +string Name
      +string JdeNumber
      +string OfficePhone
      +string MailingAddress
      +...
    }

    class Employee {
      +Guid EmployeeId
      +string FirstName
      +string LastName
      +string JdeNumber
      +...
    }

    %% Relationships
    FieldOffice --> Employee : Manager
    FieldOffice --> Employee : Lead
    FieldOffice --> Employee : Director
    Employee --> Asset : Owns
    Asset <|-- Computer
    Asset <|-- MobileDevice

Conclusion 🎯

The UpdateFieldOfficeTableWithNewColumns.Designer.cs file is your model snapshot reflecting the database schema after the UpdateFieldOfficeTableWithNewColumns migration.

  • It ensures EF Core commands have an accurate blueprint of tables, columns, keys, indexes, and relationships.
  • By following the EF Core migrations workflow, you maintain a versioned, auditable, and incremental approach to evolving your database.
  • Understanding this file helps debug migration issues, track changes over time, and keep your code‑first model and database schema in perfect sync.

Feel free to refer back to this documentation whenever you need to:

  • Verify entity configurations
  • Trace foreign‑key setups
  • Understand how TPH inheritance is mapped
  • Smoothly manage your database migrations!

Happy coding! 🚀


Generated by Entity Framework Core • Auto‑migration snapshot