πŸ“‘ Table of Contents

  1. πŸ“ Overview & Purpose
  2. πŸ”§ Dependencies & Technologies
  3. πŸ—οΈ Code Structure & Model Snapshot
  4. πŸ“Š Data Models & Entities
    4.1. Asset & Inheritance Hierarchy
    4.2. Billing Entities
    4.3. Supporting/Staging Entities
  5. πŸ”— Relationships & Navigations
  6. πŸ’Ύ Applying the Migration
  7. πŸ” BuildTargetModel Deep Dive
  8. πŸ“‹ Sample Code Blocks & Usage Examples
  9. πŸ“ˆ Entity‑Relationship (ER) Diagram (PlantUML)
  10. πŸŽ‰ Conclusion

1. πŸ“ Overview & Purpose

This fileβ€”20220303170907_AddBillingTable.Designer.csβ€”is an Entity Framework Core migration snapshot generated on 03‑31‑2022. It reflects the entire model of your database schema after applying the AddBillingTable migration.

  • Author: kvamshi
  • Context: IrbyContext
  • Migration ID: 20220303170907_AddBillingTable

Why it exists
EF Core uses this designer file to reconstruct the model when generating SQL or diffing future migrations.
Do not manually edit itβ€”changes are overwritten on dotnet ef migrations add.


2. πŸ”§ Dependencies & Technologies

Technology / Package Version Purpose
Microsoft.EntityFrameworkCore 5.0.12 Core ORM
Microsoft.EntityFrameworkCore.Migrations 5.0.12 Migration support
Microsoft.EntityFrameworkCore.Design 5.0.12 Design‑time tools
Microsoft.EntityFrameworkCore.SqlServer 5.0.12 SQL Server provider
Microsoft.EntityFrameworkCore.Storage.ValueConversion 5.0.12 Value converters support
  • .NET Target: .NET 5.0
  • Database: SQL Server (uses SqlServerValueGenerationStrategy.IdentityColumn)
  • Schema: All tables under irby by default

3. πŸ—οΈ Code Structure & Model Snapshot

[DbContext(typeof(IrbyContext))]
[Migration("20220303170907_AddBillingTable")]
partial class AddBillingTable : Migration
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        // 1. Global Annotations
        modelBuilder
            .HasAnnotation("Relational:MaxIdentifierLength", 128)
            .HasAnnotation("ProductVersion", "5.0.12")
            .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

        // 2. Entity Definitions (β‰ˆ 30+ tables / types)
        modelBuilder.Entity("IrbyImaging.DomainClasses.BillingInvoice", b => { /* … */ });
        // … other Entities …
        modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { /* … */ });

        // 3. Relationships & Navigations
        modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
            b.HasOne("FieldOffice").WithMany("Assets").HasForeignKey("FieldOfficeId");
            // …
        });
        // … other navigations …
    }
}
  • Global Annotations: Controls identifier length, EF product version, key generation strategy.
  • Entities: Each modelBuilder.Entity(...) block maps a CLR class to a database table.
  • Relationships: Fluent API calls (HasOne(), WithMany(), HasForeignKey()) define foreign keys and navigations.

4. πŸ“Š Data Models & Entities

Below is a high‑level summary of all entities registered in the model snapshot.

4.1. Asset & Inheritance Hierarchy

CLR Type Table (Schema) PK Notes / Discriminator
Asset irby.Asset Id (Guid) Base with Discriminator
β”œβ”€ Computer irby.Asset Id (Guid) Discriminator = "Computer"
β”œβ”€ DeskPhone irby.Asset Id "DeskPhone"
β”œβ”€ Dock irby.Asset Id "Dock"
β”œβ”€ MobileDevice irby.Asset Id "MobileDevice"
β”œβ”€ Monitor irby.Asset Id "Monitor"
β”œβ”€ NetworkEquipment irby.Asset Id "NetworkEquipment"
β”œβ”€ OfficePrinter irby.Asset Id "OfficePrinter"
β”œβ”€ Printer irby.Asset Id "Printer"
└─ SafetyEquipment irby.Asset Id "SafetyEquipment"

4.2. Billing Entities

CLR Type Table (Schema) PK Key Columns & Notes
BillingInvoice irby.BillingInvoice Id (Guid) New table created by this migration:
β€’ CarrierId (Guid)
β€’ GeneralLedgerId (Guid)
β€’ Charge (decimal(18,2))
β€’ AddedDate, ModifiedDate (datetime2)
β€’ FileName, JobNumber, InvoiceYearMonth

4.3. Supporting / Staging Entities

CLR Type Table (Schema) PK Purpose
CarrierType irby.CarrierType Id (Guid) Master lookup for carriers
CarrierTypeDetail irby.CarrierTypeDetail Id (Guid) Child details for CarrierType
CovidTestData irby.CovidTestData CovidTestDataId Stores COVID‑19 test results & images
DocumentImage irby.DocumentImage DocumentImageId OCR and binary storage for scanned docs
Employee irby.Employee Id (Guid) Company employees
FieldOffice irby.FieldOffice Id (Guid) Geographical offices
GeneralLedger irby.GeneralLedger Id (Guid) GL master records
GLTypeDetail irby.GLTypeDetail Id (Guid) GL sub‑types
IPMMigration irby.IPMMigration IPMMigrationId Document migration staging
Job irby.Job Id (Guid) Project/Job master
Manufacturer irby.AssetManufacturer Id (int) Asset vendor lookup
ODSEmployee irby.ODS_Employee_Staging EMPLOYEE_NUMBER Staging table from ODS feed
ODSJob irby.ODS_Jobs_Staging ORG_BU (string) Staging jobs feed
OperatingSystem irby.OperatingSystem Id (int) OS lookup
TempDocumentData irby.TempDocumentData TempDocumentDataId Temporary doc staging
AssetModel irby.AssetModel Id (int) Asset models (e.g. laptop model)
AssetModelDetail irby.AssetModelDetail Id (int) Detailed specs per model

5. πŸ”— Relationships & Navigations

Here is a bullet overview of the major relationships:

  • Asset

    • β†’ FieldOffice (many assets to one office)
    • β†’ AssetModel (many assets to one model, cascade delete)
    • β†’ Employee (Owner)
  • AssetModel

    • β†’ Manufacturer
  • AssetModelDetail

    • β†’ AssetModel
    • β†’ Manufacturer
  • CarrierTypeDetail

    • β†’ CarrierType
  • Employee

    • β†’ Job (CurrentJob)
  • FieldOffice

    • β†’ Employee (Manager)
  • GLTypeDetail

    • β†’ GeneralLedger
  • ODSEmployee

    • β†’ ODSJob
  • Computer & SafetyEquipment

    • β†’ OperatingSystem

Navigations are configured via .HasOne(), .WithMany(), .OnDelete(DeleteBehavior.Cascade) and inversely .Navigation("…") at the end.


6. πŸ’Ύ Applying the Migration

  1. Add Migration
    dotnet ef migrations add AddBillingTable
    
  2. Update Database
    dotnet ef database update
    
  3. Verify
    • Check that the irby.BillingInvoice table exists with all defined columns.
    • Confirm no breaking changes in other tables.

⚠️ The .Designer.cs file is automatically updated each time you scaffold a migration.


7. πŸ” BuildTargetModel Deep Dive

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    // 1. Annotations
    modelBuilder
      .HasAnnotation("Relational:MaxIdentifierLength", 128)
      .HasAnnotation("ProductVersion", "5.0.12")
      .HasAnnotation("SqlServer:ValueGenerationStrategy", IdentityColumn);

    // 2. BillingInvoice Entity
    modelBuilder.Entity("IrbyImaging.DomainClasses.BillingInvoice", b =>
    {
        b.Property<Guid>("Id")
         .ValueGeneratedOnAdd()
         .HasColumnType("uniqueidentifier");
        b.Property<Guid>("CarrierId")
         .HasColumnType("uniqueidentifier");
        b.Property<decimal>("Charge")
         .HasColumnType("decimal(18,2)");
        b.Property<DateTime>("AddedDate")
         .HasColumnType("datetime2");
        // … other properties …
        b.HasKey("Id");
        b.ToTable("BillingInvoice", "irby");
    });
    // 3. Other Entities
    //    modelBuilder.Entity("…", b => { … });
    // 4. Relationships (example)
    modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
    {
        b.HasOne("IrbyImaging.DomainClasses.FieldOffice", "FieldOffice")
         .WithMany("Assets")
         .HasForeignKey("FieldOfficeId");
    });
}
  • Property<>() defines column type & nullability.
  • HasKey() sets the primary key.
  • HasIndex() creates an index (unique or normal).
  • ToTable() maps to a specific schema & table.
  • Inheritance uses HasDiscriminator() to store derived types in the same table.

8. πŸ“‹ Sample Code Blocks & Usage Examples

8.1. DbContext Registration

public class IrbyContext : DbContext
{
    public DbSet<BillingInvoice> BillingInvoices { get; set; }
    // … other DbSets …

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // The snapshot in .Designer.cs is used automatically.
    }
}

8.2. Querying Billing Records

using var context = new IrbyContext();

// Add a new invoice
var invoice = new BillingInvoice
{
    CarrierId       = Guid.NewGuid(),
    GeneralLedgerId = existingLedgerId,
    Charge          = 150.75m,
    AddedDate       = DateTime.UtcNow,
    AddedBy         = "system",
    JobNumber       = "JOB1234",
    InvoiceYearMonth= "202203"
};
context.BillingInvoices.Add(invoice);
context.SaveChanges();

// Fetch invoices for a month
var marchInvoices = context.BillingInvoices
    .Where(i => i.InvoiceYearMonth == "202203")
    .ToList();

9. πŸ“ˆ Entity‑Relationship (ER) Diagram (PlantUML)

@startuml
schema "irby" {
  class Asset {
    + Guid Id
    + string Discriminator
    …
  }
  class BillingInvoice {
    + Guid Id
    + Guid CarrierId
    + Guid GeneralLedgerId
    + decimal Charge
    + DateTime AddedDate
    …
  }
  class FieldOffice { + Guid Id }
  class Employee { + Guid Id }
  class AssetModel { + int Id }
  class Manufacturer { + int Id }
  class OperatingSystem { + int Id }

  Asset --> FieldOffice
  Asset --> Employee
  Asset --> AssetModel
  AssetModel --> Manufacturer
  BillingInvoice ..> CarrierType
  BillingInvoice ..> GeneralLedger
  Computer --|> Asset
  Computer --> OperatingSystem
  SafetyEquipment --|> Asset
  SafetyEquipment --> OperatingSystem
}
@enduml

You can paste the above into any PlantUML editor to visualize the schema.


10. πŸŽ‰ Conclusion

This .Designer.cs snapshot is a read‑only blueprint of your database model after the AddBillingTable migration. It ensures EF Core can:

  • Scaffold future migrations accurately.
  • Compare model changes against the last snapshot.
  • Generate SQL scripts for schema updates.

Keep your domain classes and DbContext models in sync, and let EF Core handle the scaffoldingβ€”this file will keep you on track! πŸš€