Migration: 20240613135838_PncTable.Designer.cs 🚀


Table of Contents 🗂️

  1. Overview & Purpose
  2. Key Functional Areas
  3. Pnc Table Schema
  4. Snapshot of Domain Model
    4.1 Asset Management Entities
    4.2 Document & Imaging Entities
    4.3 Audit Entities
    4.4 HR & Employee Entities
    4.5 Finance & Operations Entities
  5. Relationships & Configurations
  6. Using EF Core Migrations
  7. Code Snippets
  8. UML Diagram
  9. Error Handling & Return Types
  10. API Endpoints Overview
  11. Third‑party Integrations
  12. Conclusion & Next Steps

1. Overview & Purpose

This auto‑generated EF Core migration file captures a snapshot of the IrbyContext domain model at the moment you ran:

dotnet ef migrations add PncTable
  • Migration ID: 20240613135838_PncTable
  • Designer File: Contains the BuildTargetModel method that EF Core uses under the hood to:
    • Map entities → tables
    • Configure columns, keys, indexes
    • Define relationships & inheritance

Note: You typically do not hand‑edit this file. Changes to your C# entity classes → re‑generate migrations.


2. Key Functional Areas

  • 🚧 BuildTargetModel
    The core method where ModelBuilder is used to configure every entity in your model.

  • 🗃️ Entity Configuration

    • .Entity(...) calls
    • Column definitions: .Property<T>(...)
    • Keys: .HasKey(...)
    • Indexes: .HasIndex(...)
    • Table mapping: .ToTable("Name","Schema")
  • 🧩 Inheritance (TPH)
    Single‑table inheritance for Asset subtypes via .HasDiscriminator().

  • ⚙️ SQL Server Annotations

    • .HasAnnotation("ProductVersion", "7.0.7")
    • UseIdentityColumns(modelBuilder)

3. Pnc Table Schema

This migration introduces the Pnc table in the irby schema:

Column Type Nullable Description
PncId (PK) uniqueidentifier No Auto‑generated on add
CardNumber nvarchar(max) Yes
CustomerWorkOrderNumber int No
DepartmentOrJobNumber int No
EmployeeJdeAB int No
FirstName nvarchar(max) Yes
LastName nvarchar(max) Yes
MCC int No Merchant Category Code
MerchantName nvarchar(max) Yes
PostingDate datetime2 No
SplitAmount decimal(18,2) No
SubLedger int No
SubLedgerType nvarchar(max) Yes
Subsidiary decimal(18,2) No
TransactionDate datetime2 No
TransactionId int No
UnitNumber int No

📦 Table: irby.Pnc


4. Snapshot of Domain Model

The designer covers all domain entities. Below is a high‑level grouping.

4.1 Asset Management Entities

Entity Schema Notes
Asset irby TPH base type
– Computer, MobileDevice, Monitor, DeskPhone, … irby Discriminator values
AssetHistory irby Tracks asset changes
AssetModel & AssetModelDetail irby / default Model definitions
Manufacturer irby Asset make lookup
Equipment, EquipmentClass, EquipmentType irby Non‑IT assets

4.2 Document & Imaging Entities

  • DocumentImage / DocumentType / DocumentCategory
  • DocumentAttribute
  • Temporary & Migration tables: TempDocumentData, BlobData, IPMMigration, IrbyForms
  • Property/Lease details: GeoLocation, LeaseDetails, LeasePropertyDetails

4.3 Audit Entities

  • AuditDetail
  • AuditReport

4.4 HR & Employee Entities

  • Employee, Department
  • Role, Permissions
  • Linking tables: LinkUserRole, LinkRolePermission
  • Timesheets: TimeEntryType, TimeSheetEntry
  • Tickets & Updates: Ticket, Update

4.5 Finance & Operations Entities

  • BillingInvoice, GeneralLedger, GLTypeDetail
  • ContractTypeDetails, ContractTypeNumber, ContractsByLead
  • PurchaseOrder, WorkOrder
  • WIP (Work In Progress)
  • Pnc (new)
  • CarrierType, CarrierTypeDetail, RequestOption

5. Relationships & Configurations 🔗

  • Primary Keys: b.HasKey("…")
  • Indexes: b.HasIndex("…") (unique filters on some columns)
  • Foreign Keys:
    b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
     .WithMany("Employees")
     .HasForeignKey("JobId")
     .OnDelete(DeleteBehavior.Cascade)
     .IsRequired();
    
  • Cascade Delete: Configured via .OnDelete(DeleteBehavior.Cascade)
  • TPH Inheritance:
    modelBuilder.Entity("IrbyImaging.DomainClasses.Asset")
        .HasDiscriminator<string>("Discriminator")
        .HasValue("Asset");
    

6. Using EF Core Migrations 🛠️

# Generate a new snapshot
dotnet ef migrations add PncTable

# Apply all pending migrations
dotnet ef database update

# Generate SQL script for review
dotnet ef migrations script 20240613135838_PncTable

The Designer file is read‑only in day‑to‑day work.
All model changes come from your C# entity classes + the Up()/Down() methods in the main migration file.


7. Code Snippets 💻

BuildTargetModel Signature

[DbContext(typeof(IrbyContext))]
[Migration("20240613135838_PncTable")]
partial class PncTable
{
    /// <inheritdoc />
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        modelBuilder
            .HasAnnotation("ProductVersion", "7.0.7")
            .HasAnnotation("Relational:MaxIdentifierLength", 128);

        SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

        // … entity configurations …
    }
}

Pnc Entity Mapping

modelBuilder.Entity("IrbyImaging.DomainClasses.Pnc", b =>
{
    b.Property<Guid>("PncId")
      .ValueGeneratedOnAdd()
      .HasColumnType("uniqueidentifier");

    b.Property<string>("CardNumber").HasColumnType("nvarchar(max)");
    b.Property<int>("CustomerWorkOrderNumber").HasColumnType("int");
    // … other properties …
    b.HasKey("PncId");
    b.ToTable("Pnc", "irby");
});

8. UML Diagram 📈

+------------------------------------------------+
|                   Pnc                          |
+------------------------------------------------+
| - PncId : Guid         <<PK>>                  |
| - CardNumber : string                           |
| - CustomerWorkOrderNumber : int                 |
| - DepartmentOrJobNumber : int                   |
| - EmployeeJdeAB : int                           |
| - FirstName : string                            |
| - LastName : string                             |
| - MCC : int                                     |
| - MerchantName : string                         |
| - PostingDate : DateTime                        |
| - SplitAmount : Decimal                         |
| - SubLedger : int                               |
| - SubLedgerType : string                        |
| - Subsidiary : Decimal                          |
| - TransactionDate : DateTime                    |
| - TransactionId : int                           |
| - UnitNumber : int                              |
+------------------------------------------------+

9. Error Handling & Return Types ⚠️

  • Designer code uses Fluent API; misconfigurations will surface as exceptions at startup/migration time.
  • No custom error‑handling or return types—pure model mapping.

10. API Endpoints Overview 🛣️

Not applicable.
This file does not define Web API controllers or endpoints.


11. Third‑party Integrations 🔌

  • Entity Framework Core (Microsoft.EntityFrameworkCore)
    • EF Core SQL Server provider
  • No other external libraries in play here.

12. Conclusion & Next Steps ✅

  • 🎯 Purpose: Introduce the Pnc entity and capture a complete model snapshot.
  • 🔍 Inspect the corresponding 20240613135838_PncTable.cs (Up/Down) for actual DDL SQL.
  • 🚀 Deploy by running dotnet ef database update.
  • 📦 Best Practice: Always check Designer diff in source control to ensure your model changes are correct.

Happy coding! 🏗️✨