π Documentation: 20240613135838_PncTable.cs Migration
π Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- Data Models (Table Schema)
- EF Core Migration Workflow
- Helper Methods & Utilities
- Error Handling & Return Types
- API Endpoints Overview
- Third-Party Integrations
- UML Class Diagram
- Sample Code Blocks
- Usage Examples
- 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
Pnctable with appropriate columns & data types. - Down: Drop the
Pnctable to roll back the change.
- Up: Create a strongly typed
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.EntityFrameworkCoreMicrosoft.EntityFrameworkCore.SqlServerMicrosoft.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
- Create Migration
dotnet ef migrations add PncTable --project IrbyImaging.DbContext - Apply Migration
dotnet ef database update --project IrbyImaging.DbContext
- The
Upmethod executes ondatabase update. - The
Downmethod 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()andMigrationBuilder.DropTable().
7. Error Handling & Return Types
- Return Type: Both
UpandDownarevoid. - 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
-
Add the Migration
cd IrbyImaging.DbContext dotnet ef migrations add PncTable -
Review the Generated SQL
dotnet ef migrations script -
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! π