πŸ“„ IrbyImaging.DbContext Migrations

File: 20220622145439_AddNewCategoryTable.Designer.cs


πŸš€ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. Model Snapshot & Fluent API Configuration
    4.1. Global Annotations
    4.2. Asset Management Entities
    4.3. Document Management Entities
    4.4. Human Resources Entities
    4.5. Billing & Finance Entities
    4.6. Other Domain Entities
  5. Entity Relationships (UML Diagram)
  6. How to Use & Generate Migrations
  7. Sample Code Blocks
  8. Conclusion

1. Overview & Purpose

πŸ”Ž What is this file?
This file is an auto-generated EF Core Designer snapshot for the migration named AddNewCategoryTable (timestamp: 20220622145439). It belongs to the IrbyImaging.DbContext assembly and captures the complete database model after applying that migration.

πŸ“Œ Why does it exist?

  • Enables EF Core to compare the current model against the previous snapshot when you create new migrations.
  • Ensures consistency between your C# domain classes and the underlying database schema.
  • Do not modify manually; it’s maintained by the EF tooling.

2. Key Functional Areas

  • πŸ”§ BuildTargetModel: Core method that configures every entity, property, relationship, table mapping, index, discriminator, etc.
  • πŸ—‚ Attribute Annotations
    • [DbContext(typeof(IrbyContext))] links this migration to your IrbyContext.
    • [Migration("20220622145439_AddNewCategoryTable")] marks the unique migration ID.
  • πŸ“¦ Entity Configuration via Fluent API (modelBuilder.Entity(...)).
  • πŸ”€ Inheritance mapped as Table-Per-Hierarchy (TPH) for Asset and its derived types.
  • πŸ” Indexes and Keys defined for performance and constraints.
  • 🌐 Schema Mapping (ToTable("...", "irby")) – all objects live in the irby schema.

3. Dependencies & Technologies

Technology / Package Version / Notes
.NET Core / .NET 5.0+ Target framework
Microsoft.EntityFrameworkCore 5.0.12 (as per annotation)
Microsoft.EntityFrameworkCore.Relational SQL Server provider
Microsoft.EntityFrameworkCore.Migrations Migration scaffolding & tooling
SQL Server Underlying database

4. Model Snapshot & Fluent API Configuration

4.1 Global Annotations

modelBuilder
  .HasAnnotation("Relational:MaxIdentifierLength", 128)
  .HasAnnotation("ProductVersion", "5.0.12")
  .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
  • MaxIdentifierLength: Limits table & column name length to 128 characters.
  • ProductVersion: EF Core version when snapshot was created.
  • ValueGenerationStrategy: Default for key generation is IdentityColumn.

4.2 Asset Management Entities πŸ–₯οΈπŸ“¦

Entity Table PK Type Key Notes
Asset irby.Asset GUID Base class for all asset types
AssetHistory irby.AssetHistory GUID Tracks changes on assets
AssetModel irby.AssetModel int Models of assets (e.g. laptop)
AssetModelDetail AssetModelDetail int Additional specs per model
Manufacturer irby.AssetManufacturer int Make of the model
OperatingSystem irby.OperatingSystem int OS options
Computer, DeskPhone, … TPH on irby.Asset Discriminator Derived from Asset

Highlights

  • TPH Inheritance:
    modelBuilder.Entity("IrbyImaging.DomainClasses.Asset")
      .HasDiscriminator<string>("Discriminator")
      .HasValue("Asset");
    modelBuilder.Entity("IrbyImaging.DomainClasses.Computer")
      .HasBaseType("IrbyImaging.DomainClasses.Asset")
      .HasDiscriminator().HasValue("Computer");
    
  • Relationships:
    • Asset β†’ AssetModel (required, cascade on delete)
    • Asset β†’ Employee (owner)
    • Asset β†’ FieldOffice

4.3 Document Management Entities πŸ“πŸ—‚

Entity Table PK Type Description
DocumentAttribute irby.DocumentAttribute GUID Defines metadata attributes
DocumentCategory irby.DocumentCategory GUID NEW category table added in this migration
DocumentType irby.DocumentType GUID Type names, classification
DocumentImage irby.DocumentImage GUID Binary contents + OCR data
IrbyForms irby.IrbyForms GUID Form images
IPMMigration irby.IPMMigration GUID Legacy migration staging
TempDocumentData irby.TempDocumentData GUID Temporary ingest table

Example: DocumentCategory

modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentCategory", b =>
{
  b.Property<Guid>("Id").ValueGeneratedOnAdd().HasColumnType("uniqueidentifier");
  b.Property<string>("Name").HasColumnType("nvarchar(max)");
  b.Property<string>("Description").HasColumnType("nvarchar(max)");
  b.Property<bool>("IsAvailable").HasColumnType("bit");
  b.Property<bool>("IsDeleted").HasColumnType("bit");
  b.Property<string>("AddedBy").HasColumnType("nvarchar(max)");
  b.Property<DateTime>("AddedDate").HasColumnType("datetime2");
  b.Property<string>("ModifiedBy").HasColumnType("nvarchar(max)");
  b.Property<DateTime>("ModifiedDate").HasColumnType("datetime2");
  b.HasKey("Id");
  b.ToTable("DocumentCategory", "irby");
});

4.4 Human Resources Entities πŸ‘₯🏒

Entity Table PK Type Notes
Employee irby.Employee GUID Tracks users with unique JdeNumber
FieldOffice irby.FieldOffice GUID Business units, managers, superintendents
Job irby.Job GUID JDE job numbers
ODSEmployee irby.ODS_Employee_Staging string Staging table for ODS feed
ODSJob irby.ODS_Jobs_Staging string Staging table for ODS jobs
  • Unique Index:
    • Employee.JdeNumber
    • FieldOffice.JdeNumber
    • Job.JdeNumber
  • Relationships:
    • Employee β†’ Job (current job)
    • FieldOffice β†’ Employee (manager, project manager, superintendent)

4.5 Billing & Finance Entities πŸ’°πŸ“Š

Entity Table PK Type Description
BillingInvoice irby.BillingInvoice GUID Invoice records
GeneralLedger irby.GeneralLedger GUID GL master
GLTypeDetail GLTypeDetail GUID GL sub-codes
CarrierType irby.CarrierType GUID Carrier categories
CarrierTypeDetail CarrierTypeDetail GUID Carrier type child records

4.6 Other Domain Entities 🧩

Entity Table PK Type Purpose
CovidTestData irby.CovidTestData GUID COVID testing records
Issue irby.Issue GUID Generic issue catalog
RequestOption irby.RequestOption GUID UI dropdown options
Ticket irby.Ticket GUID Support tickets
Update irby.Update GUID Ticket status history

5. Entity Relationships (UML Diagram)

classDiagram
  %% Base / Derived
  Asset <|-- Computer : Discriminator="Computer"
  Asset <|-- MobileDevice : Discriminator="MobileDevice"
  Asset <|-- DeskPhone : Discriminator="DeskPhone"
  Asset <|-- Monitor : Discriminator="Monitor"
  Asset <|-- Dock : Discriminator="Dock"
  Asset <|-- NetworkEquipment : Discriminator="NetworkEquipment"
  Asset <|-- OfficePrinter : Discriminator="OfficePrinter"
  Asset <|-- Printer : Discriminator="Printer"
  Asset <|-- SafetyEquipment : Discriminator="SafetyEquipment"

  %% Asset Relationships
  Asset o-- AssetModel : modelId
  Asset o-- Employee : ownerId
  Asset o-- FieldOffice : fieldOfficeId

  %% Model Details
  AssetModel "1" o-- "*" AssetModelDetail
  AssetModel "*" --> "1" Manufacturer : makeId

  %% Document Management
  DocumentCategory --> DocumentType : DocumentCategory (string)
  DocumentType --> DocumentImage : ReferenceId

  %% Ticketing
  Ticket "1" o-- "*" Update : ticketId

6. How to Use & Generate Migrations

  1. 🎯 Add a Migration
    dotnet ef migrations add AddNewCategoryTable \
      --context IrbyContext
    
  2. πŸ” Inspect the Generated Files
    • 20220622145439_AddNewCategoryTable.cs β†’ Contains Up() / Down() methods.
    • 20220622145439_AddNewCategoryTable.Designer.cs β†’ Model snapshot (this file).
  3. πŸš€ Apply to Database
    dotnet ef database update --context IrbyContext
    
  4. πŸ”„ Subsequent Migrations
    EF Core diff between this snapshot and your current DbContext model to scaffold the next migration.

7. Sample Code Blocks

7.1 Class Declaration & Metadata

[DbContext(typeof(IrbyContext))]
[Migration("20220622145439_AddNewCategoryTable")]
partial class AddNewCategoryTable : Migration
{
    // This designer file contains BuildTargetModel only.
    // The Up/Down are in the main AddNewCategoryTable.cs.
}

7.2 Global Fluent API

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
  #pragma warning disable 612, 618
  modelBuilder
    .HasAnnotation("Relational:MaxIdentifierLength", 128)
    .HasAnnotation("ProductVersion", "5.0.12")
    .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
  
  // Entity configurations go here...
  #pragma warning restore 612, 618
}

8. Conclusion

βœ… This Designer file is a critical part of Entity Framework Core’s migration infrastructure. It provides a point-in-time snapshot of your entire modelβ€”ensuring that future migrations are correctly generated. In this particular migration, the DocumentCategory entity (the β€œNewCategoryTable”) was introduced, enabling robust document classification within the IrbyImaging system.


Happy coding & smooth migrations! πŸš€
β€” IrbyImaging Development Team