๐Ÿ“‘ 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

  1. ๐Ÿ” Overview & Purpose
  2. ๐Ÿ›  Dependencies & Technologies
  3. ๐Ÿš€ Key Functional Areas
  4. ๐Ÿ—„ Data Model: BillingInvoice Table
  5. ๐Ÿ”ง Helper Methods & Utilities
  6. โŒ Error Handling & Return Types
  7. ๐ŸŒ API Endpoints Overview
  8. ๐Ÿ”— Thirdโ€‘Party Integrations
  9. ๐Ÿ’ก Usage & Migration Examples
  10. ๐Ÿ” Sample Code Blocks
  11. ๐Ÿ“Š UML Diagrams
  12. โœ… 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 named BillingInvoice under the irby schema. 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

  1. Migration Class

    • Inherits from Migration (EF Core).
    • Implements two essential methods:
      • Up(MigrationBuilder migrationBuilder)
        Creates the BillingInvoice table with all columns and primary key.
      • Down(MigrationBuilder migrationBuilder)
        Drops the BillingInvoice table, rolling back the schema change.
  2. Schema Definition

    • Schema: irby
    • Table: BillingInvoice

๐Ÿ—„ 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 Up and Down methods have a void return 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

  1. Add Migration
    dotnet ef migrations add AddBillingTable \
        --project IrbyImaging.DbContext \
        --startup-project IrbyImaging.WebApi
    
  2. Apply Migration
    dotnet ef database update \
        --project IrbyImaging.DbContext \
        --startup-project IrbyImaging.WebApi
    
  3. 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! ๐Ÿš€