📖 Documentation for 20230711153123_AddCategoryColumn.Designer.cs

Location: IrbyImaging.DbContext/Migrations/20230711153123_AddCategoryColumn.Designer.cs
Generated By: Entity Framework Core Migrations (auto-generated)
Migration Name: AddCategoryColumn


🚀 Table of Contents

  1. 🔍 Overview & Purpose
  2. ⚙️ Dependencies & Technologies
  3. 🏗️ Migration File Structure
  4. 🗄️ Entity Data Models
    • 4.1. Asset‑Related Models
    • 4.2. Document‑Related Models
    • 4.3. Billing, Ticketing, Auditing Models
    • 4.4. ODS & Integration Staging Models
  5. ➕ Category Column Addition
  6. 🛠️ BuildTargetModel Explained
  7. 🔗 Relationships & Navigation Properties
  8. 🚀 How to Apply / Use the Migration
  9. 🧩 Third‑Party Integrations
  10. 🎉 Conclusion

🔍 Overview & Purpose

This Designer file is an auto‐generated snapshot of the Entity Framework Core model after applying the AddCategoryColumn migration. It defines:

  • The complete schema of all database tables (irby schema).
  • Data types, keys, indices, property configurations, and relationships between entities.
  • A category column added to specific entities so that assets and asset models can be grouped or filtered by category.

Note:

  • Do not modify this file manually – it is managed by EF Core.
  • Alterations should be done via EF Migrations (Up/Down in the main migration file), then re‑scaffolded.

⚙️ Dependencies & Technologies

Technology Version Purpose
Microsoft.EntityFrameworkCore 7.0.7 ORM, model building, migrations
Microsoft.EntityFrameworkCore.SqlServer 7.0.7 SQL Server provider
C# / .NET 7.0 — Language & runtime
SQL Server ≥ 2016 Target database

🏗️ Migration File Structure

namespace IrbyImaging.DbContext.Migrations
{
    [DbContext(typeof(IrbyContext))]
    [Migration("20230711153123_AddCategoryColumn")]
    partial class AddCategoryColumn
    {
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            // 1. Annotations (product version, identifiers)
            // 2. Identity column strategies
            // 3. All entity configurations
            // 4. Table & schema mapping
            // 5. Discriminator (TPH) for Asset hierarchy
            // 6. Relationships & navigation setup
        }
    }
}
  • Attributes
    • [DbContext(typeof(IrbyContext))]: Indicates the context class.
    • [Migration("20230711153123_AddCategoryColumn")]: Unique timestamped migration ID.
  • BuildTargetModel
    • Constructs the EF Core model snapshot, used for future diffs and ensuring consistency.

🗄️ Entity Data Models

Below is a high‑level grouping of the entities configured in this migration. All tables are in the irby schema unless otherwise noted.

4.1. Asset‑Related Models

Entity Table Notes
Asset irby.Asset Base type (TPH) with discriminator “Asset”
Computer irby.Asset Inherits Asset (Discriminator = “Computer”)
DeskPhone irby.Asset … “DeskPhone”
Dock irby.Asset … “Dock”
MobileDevice irby.Asset Carrier, IMEI, Telogis flag
Monitor irby.Asset … “Monitor”
NetworkEquipment irby.Asset … “NetworkEquipment”
OfficePrinter irby.Asset Company, ContractEndDate
Printer irby.Asset … “Printer”
SafetyEquipment irby.Asset AssetNumber, CPSNumber, OS, UnitNumber
AssetHistory irby.AssetHistory Tracks changes & status history
AssetModel irby.AssetModel Models metadata (Name, Type, Category...)
AssetModelDetail AssetModelDetail Details per model + Category integer
Manufacturer irby.AssetManufacturer Makers of assets
OperatingSystem irby.OperatingSystem OS options for Computers / SafetyEquipment

4.2. Document‑Related Models

Entity Table Notes
DocumentAttribute irby.DocumentAttribute Custom attributes, types, flags
DocumentCategory irby.DocumentCategory Category lookup
DocumentType irby.DocumentType Document type definitions
DocumentImage irby.DocumentImage Binary image/OCR content, tagging
TempDocumentData irby.TempDocumentData Staging for indexing, blob linking
BlobData irby.BlobData Raw binary data
IPMMigration irby.IPMMigration Legacy migration staging
IrbyForms irby.IrbyForms PDF/form image storage

4.3. Billing, Ticketing, Auditing Models

  • Billing & Carrier

    • BillingInvoice (irby.BillingInvoice)
    • CarrierType / CarrierTypeDetail
  • Ticketing & Updates

    • Ticket (irby.Ticket)
    • Update (irby.Update)
  • Time & Payroll

    • TimeEntryType (irby.TimeEntryType)
    • TimeSheetEntry (irby.TimeSheetEntry)

4.4. ODS & Integration Staging Models

Entity Table Purpose
ODSJob ODS_Jobs_Staging Staging table for ODS job data
ODSEmployee ODS_Employee_Staging Staging table for employees

➕ Category Column Addition

This migration introduces a Category field to various entities to enable richer classification:

Entity Property Type Required?
Asset Category string Yes
AssetModel Category string Yes
AssetModelDetail Category int No
Plus many document/ticket/time‑entry tables also have a Category or AttributeType column.

Why?

  • Filter assets by category (e.g., “Computer”, “Safety”).
  • Model‑level grouping for drop‑down selection.
  • Allow integer‑backed enums on detail tables.

🛠️ BuildTargetModel Explained

Inside BuildTargetModel(ModelBuilder modelBuilder), EF Core:

  1. Sets annotations:

    modelBuilder
      .HasAnnotation("ProductVersion", "7.0.7")
      .HasAnnotation("Relational:MaxIdentifierLength", 128);
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
    
  2. Defines every entity via modelBuilder.Entity("FullTypeName", b => { ... }).

  3. Configures each property:

    b.Property<Guid>("Id")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");
    
  4. Sets primary keys & indices:

    b.HasKey("Id");
    b.HasIndex("FieldOfficeId");
    
  5. Maps to table & schema:

    b.ToTable("Asset", "irby");
    
  6. Configures Table‑Per‑Hierarchy (TPH) inheritance for Asset and its subtypes using .HasDiscriminator().

  7. Defines relationships & navigation via HasOne(...).WithMany(...) calls.


🔗 Relationships & Navigation Properties

Below is a sample of how relationships are wired:

// Asset → FieldOffice (many assets belong to one office)
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.FieldOffice", "FieldOffice")
     .WithMany("Assets")
     .HasForeignKey("FieldOfficeId");
});

// AssetModel → Manufacturer (many models per manufacturer)
modelBuilder.Entity("IrbyImaging.DomainClasses.AssetModel", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.Manufacturer", "Make")
     .WithMany("Models")
     .HasForeignKey("MakeId")
     .OnDelete(DeleteBehavior.Cascade);
});

UML Class Diagram (Excerpt)

@startuml
class Asset {
  +Guid Id
  +string Category
  +string Status
  -- 
  +FieldOfficeId
  +OwnerId
  +ModelId
}
class AssetModel {
  +int Id
  +string Category
  +string Name
}
class Manufacturer {
  +int Id
  +string Name
}
AssetModel --> Manufacturer : Make
Asset --> AssetModel : Model
Asset --> FieldOffice
@enduml

🚀 How to Apply / Use the Migration

  1. Ensure EF Core Tools are installed:
    dotnet tool install --global dotnet-ef
    
  2. Add & Update (if not already done):
    dotnet ef migrations add AddCategoryColumn
    
  3. Review the generated *.cs files in Migrations/.
  4. Apply to your database:
    dotnet ef database update 20230711153123_AddCategoryColumn
    
  5. Verify the new Category columns exist in target tables (SELECT TOP 1 Category FROM irby.Asset;).

🧩 Third‑Party Integrations

  • Entity Framework Core – automatically generates this file.
  • SQL Server – target RDBMS for identity/column mapping.
  • PlantUML – optional for diagramming your model relationships.

🎉 Conclusion

The 20230711153123_AddCategoryColumn.Designer.cs file is a complete snapshot of your EF Core model after adding Category columns to key tables. It ensures:

  • Consistency: EF Core knows exactly how your database is structured.
  • Migrations: Future schema changes will be correctly diffed against this snapshot.
  • Documentation: Serves as a code‐first reference for all entities, properties, and relationships.

✨ With this migration applied, your application can now categorize assets and models more flexibly, enabling richer data queries and UI grouping!