πŸ“š Documentation: 20240613135838_PncTable.cs Migration


πŸš€ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. Data Models (Table Schema)
  5. EF Core Migration Workflow
  6. Helper Methods & Utilities
  7. Error Handling & Return Types
  8. API Endpoints Overview
  9. Third-Party Integrations
  10. UML Class Diagram
  11. Sample Code Blocks
  12. Usage Examples
  13. Conclusion

1. Overview & Purpose

This Entity Framework Core migration PncTable is responsible for adding (and removing) the Pnc table in the irby schema of the database. The table captures transaction-level details (PNC stands for β€œPurchase, Not Classified” or custom name) such as card numbers, merchant names, amounts, and related identifiers.

  • πŸ“… Timestamp: 2024-06-13 13:58:38
  • πŸ“‚ Namespace: IrbyImaging.DbContext.Migrations
  • 🎯 Primary Goal:
    • Up: Create a strongly typed Pnc table with appropriate columns & data types.
    • Down: Drop the Pnc table to roll back the change.

2. Key Functional Areas

Method Responsibility
Up Builds the irby.Pnc table with columns, types, primary key, etc.
Down Removes (DROP TABLE) the irby.Pnc table to undo the migration.

3. Dependencies & Technologies

  • .NET & C#
  • Entity Framework Core
  • Microsoft.EntityFrameworkCore.Migrations
  • SQL Server (inferred by use of datetime2, uniqueidentifier, decimal(18,2))
  • NuGet Packages:
    • Microsoft.EntityFrameworkCore
    • Microsoft.EntityFrameworkCore.SqlServer
    • Microsoft.EntityFrameworkCore.Design

4. Data Models (Table Schema)

The migration defines the following schema:

Column Name CLR Type SQL Type Nullable Description
PncId Guid uniqueidentifier No Primary Key
PostingDate DateTime datetime2 No Date the entry was posted
TransactionId int int No System transaction identifier
DepartmentOrJobNumber int int No Department or job code
Subsidiary decimal decimal(18,2) No Subsidiary financial code value
SubLedger int int No Sub-ledger numeric code
SubLedgerType string nvarchar(max) Yes Optional text descriptor of sub-ledger
CustomerWorkOrderNumber int int No Customer work order reference
UnitNumber int int No Unit or asset number
EmployeeJdeAB int int No Employee JDE alternate business unit code
LastName string nvarchar(max) Yes Employee last name
FirstName string nvarchar(max) Yes Employee first name
CardNumber string nvarchar(max) Yes Masked or actual card number
TransactionDate DateTime datetime2 No Date/time when transaction occurred
SplitAmount decimal decimal(18,2) No Pro-rated split amount
MerchantName string nvarchar(max) Yes Name of the merchant
MCC int int No Merchant Category Code

5. EF Core Migration Workflow

  1. Create Migration
    dotnet ef migrations add PncTable --project IrbyImaging.DbContext
    
  2. Apply Migration
    dotnet ef database update --project IrbyImaging.DbContext
    
  • The Up method executes on database update.
  • The Down method executes if you rollback or remove this migration.

6. Helper Methods & Utilities

There are no additional helper methods in this migration. It relies on MigrationBuilder.CreateTable() and MigrationBuilder.DropTable().


7. Error Handling & Return Types

  • Return Type: Both Up and Down are void.
  • Error Handling: EF Core wraps DDL commands in transactions. On failure, an exception is thrown and migration is aborted.

8. API Endpoints Overview

❌ This class does not expose any HTTP or gRPC endpoints.
It purely defines database structure changes.


9. Third-Party Integrations

  • Entity Framework Core is the only external integration here.

10. UML Class Diagram

classDiagram
    %% Migration Class
    class PncTable {
        <<Migration>>
        + void Up(MigrationBuilder)
        + void Down(MigrationBuilder)
    }

    %% Pnc Entity (database table representation)
    class Pnc {
        + Guid PncId
        + DateTime PostingDate
        + int TransactionId
        + int DepartmentOrJobNumber
        + decimal Subsidiary
        + int SubLedger
        + string SubLedgerType
        + int CustomerWorkOrderNumber
        + int UnitNumber
        + int EmployeeJdeAB
        + string LastName
        + string FirstName
        + string CardNumber
        + DateTime TransactionDate
        + decimal SplitAmount
        + string MerchantName
        + int MCC
    }

    PncTable  -->  Pnc : creates/drops

11. Sample Code Blocks

Migration Class (PncTable)

public partial class PncTable : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateTable(
            name: "Pnc",
            schema: "irby",
            columns: table => new
            {
                PncId                   = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                PostingDate             = table.Column<DateTime>(type: "datetime2", nullable: false),
                TransactionId           = table.Column<int>(type: "int", nullable: false),
                DepartmentOrJobNumber   = table.Column<int>(type: "int", nullable: false),
                Subsidiary              = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                SubLedger               = table.Column<int>(type: "int", nullable: false),
                SubLedgerType           = table.Column<string>(type: "nvarchar(max)", nullable: true),
                CustomerWorkOrderNumber = table.Column<int>(type: "int", nullable: false),
                UnitNumber              = table.Column<int>(type: "int", nullable: false),
                EmployeeJdeAB           = table.Column<int>(type: "int", nullable: false),
                LastName                = table.Column<string>(type: "nvarchar(max)", nullable: true),
                FirstName               = table.Column<string>(type: "nvarchar(max)", nullable: true),
                CardNumber              = table.Column<string>(type: "nvarchar(max)", nullable: true),
                TransactionDate         = table.Column<DateTime>(type: "datetime2", nullable: false),
                SplitAmount             = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                MerchantName            = table.Column<string>(type: "nvarchar(max)", nullable: true),
                MCC                     = table.Column<int>(type: "int", nullable: false)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_Pnc", x => x.PncId);
            });
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropTable(name: "Pnc", schema: "irby");
    }
}

12. Usage Examples

  1. Add the Migration

    cd IrbyImaging.DbContext
    dotnet ef migrations add PncTable
    
  2. Review the Generated SQL

    dotnet ef migrations script
    
  3. Apply to Database

    dotnet ef database update
    

13. Conclusion

πŸŽ‰ This migration introduces the irby.Pnc table, enabling the application to persist detailed transaction records in a structured, query-friendly manner. By following EF Core’s Up/Down patterns, you can confidently apply or revert this schema change across development, staging, and production environments.


Happy Coding! πŸš€