๐ AddBillingTable Migration Documentation
Welcome to the comprehensive documentation for the AddBillingTable Entity Framework Core migration located at
IrbyImaging.DbContext/Migrations/20220303170907_AddBillingTable.cs.
This guide will walk you through every aspect of the migration: its purpose, implementation details, schema design, usage examples, and integration points.
๐ Table of Contents
- ๐ Overview & Purpose
- ๐ Dependencies & Technologies
- ๐ Key Functional Areas
- ๐ Data Model: BillingInvoice Table
- ๐ง Helper Methods & Utilities
- โ Error Handling & Return Types
- ๐ API Endpoints Overview
- ๐ ThirdโParty Integrations
- ๐ก Usage & Migration Examples
- ๐ Sample Code Blocks
- ๐ UML Diagrams
- โ Conclusion
๐ Overview & Purpose
File: 20220303170907_AddBillingTable.cs
Namespace: IrbyImaging.DbContext.Migrations
Author: kvamshi
Created/Modified: 03-31-2022
Purpose
This migration adds a new table namedBillingInvoiceunder theirbyschema. It centralizes invoice data for carrier billing, enabling the application to store, query, and manage billing invoices.
๐ Dependencies & Technologies
| Technology / Package | Version | Purpose |
|---|---|---|
| Microsoft.EntityFrameworkCore | 5.x / 6.x | Core ORM framework |
| Microsoft.EntityFrameworkCore.Relational | 5.x / 6.x | Provider for relational databases |
| Microsoft.EntityFrameworkCore.Tools | 5.x / 6.x | CLI tooling for migrations |
| .NET (C#) | .NET 5 / .NET 6 | Language and runtime |
๐ Key Functional Areas
-
Migration Class
- Inherits from
Migration(EF Core). - Implements two essential methods:
Up(MigrationBuilder migrationBuilder)
Creates theBillingInvoicetable with all columns and primary key.Down(MigrationBuilder migrationBuilder)
Drops theBillingInvoicetable, rolling back the schema change.
- Inherits from
-
Schema Definition
- Schema:
irby - Table:
BillingInvoice
- Schema:
๐ Data Model: BillingInvoice Table
Below is the table structure introduced by this migration.
| Column | .NET Type | SQL Type | Nullable | Description |
|---|---|---|---|---|
| Id | Guid |
uniqueidentifier |
No | Primary Key |
| CarrierId | Guid |
uniqueidentifier |
No | FK to Carrier entity (if exists) |
| InvoiceYearMonth | string |
nvarchar(max) |
Yes | E.g. โ2022-03โ |
| PhoneNumber | string |
nvarchar(max) |
Yes | Customer phone number |
| FirstName | string |
nvarchar(max) |
Yes | Customer first name |
| LastName | string |
nvarchar(max) |
Yes | Customer last name |
| Charge | decimal |
decimal(18,2) |
No | Amount billed |
| JobNumber | string |
nvarchar(max) |
Yes | Internal job reference |
| GeneralLedgerId | Guid |
uniqueidentifier |
No | FK to General Ledger entry |
| FileName | string |
nvarchar(max) |
Yes | Source file name |
| AddedBy | string |
nvarchar(max) |
Yes | Username who added |
| AddedDate | DateTime |
datetime2 |
No | Creation timestamp |
| ModifiedBy | string |
nvarchar(max) |
Yes | Username who last updated |
| ModifiedDate | DateTime |
datetime2 |
No | Last modification timestamp |
Primary Key Constraint
table.PrimaryKey("PK_BillingInvoice", x => x.Id);
๐ง Helper Methods & Utilities
This migration leverages the standard MigrationBuilder API provided by EF Core:
CreateTable(...)DropTable(...)
No custom utility methods are defined within this file.
โ Error Handling & Return Types
- Both
UpandDownmethods have avoidreturn type. - Exceptions during migration (e.g., SQL errors) will bubble up and halt the update processโstandard EF Core behavior.
- No explicit try/catch is implemented here; EF Core handles transaction and rollback.
๐ API Endpoints Overview
This is a database migration file.
There are no HTTP API endpoints defined or modified here.
๐ ThirdโParty Integrations
- Entity Framework Core
Migration APIs are part of EF Coreโs Relational provider.
๐ก Usage & Migration Examples
- Add Migration
dotnet ef migrations add AddBillingTable \ --project IrbyImaging.DbContext \ --startup-project IrbyImaging.WebApi - Apply Migration
dotnet ef database update \ --project IrbyImaging.DbContext \ --startup-project IrbyImaging.WebApi - Rolling Back
dotnet ef database update LastGoodMigration
๐ Sample Code Blocks
1. The Migration Class
public partial class AddBillingTable : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "BillingInvoice",
schema: "irby",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
CarrierId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
InvoiceYearMonth = table.Column<string>(type: "nvarchar(max)", nullable: true),
// ... other columns ...
ModifiedDate = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_BillingInvoice", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BillingInvoice",
schema: "irby");
}
}
2. POCO Entity Representation
(Not generated by migration, but typically accompanies it in your DbContext.)
public class BillingInvoice
{
public Guid Id { get; set; }
public Guid CarrierId { get; set; }
public string InvoiceYearMonth { get; set; }
public string PhoneNumber { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public decimal Charge { get; set; }
public string JobNumber { get; set; }
public Guid GeneralLedgerId { get; set; }
public string FileName { get; set; }
public string AddedBy { get; set; }
public DateTime AddedDate { get; set; }
public string ModifiedBy { get; set; }
public DateTime ModifiedDate { get; set; }
}
3. Query Example
using(var context = new IrbyDbContext())
{
var invoices = context.BillingInvoice
.Where(b => b.InvoiceYearMonth == "2022-03")
.ToList();
}
๐ UML Diagrams
1. Class Diagram (Mermaid)
classDiagram
class Migration {
<<abstract>>
+void Up(MigrationBuilder)
+void Down(MigrationBuilder)
}
class AddBillingTable {
+void Up(MigrationBuilder)
+void Down(MigrationBuilder)
}
Migration <|-- AddBillingTable
2. EntityโRelationship (BillingInvoice)
erDiagram
BILLINGINVOICE {
GUID Id PK
GUID CarrierId
VARCHAR InvoiceYearMonth
VARCHAR PhoneNumber
DECIMAL Charge
DATETIME AddedDate
DATETIME ModifiedDate
}
โ Conclusion
โจ The AddBillingTable migration seamlessly extends your database schema by introducing the irby.BillingInvoice table, storing all essential billing information.
- Up: Defines and creates the new table.
- Down: Cleans up by dropping it.
By following the Usage & Migration Examples, you can apply or roll back this change in your development, staging, or production environment.
This migration is a crucial building block for any billing workflows in IrbyImaging.
Happy Coding! ๐