π Table of Contents
- π Overview & Purpose
- π§ Dependencies & Technologies
- ποΈ Code Structure & Model Snapshot
- π Data Models & Entities
4.1. Asset & Inheritance Hierarchy
4.2. Billing Entities
4.3. Supporting/Staging Entities - π Relationships & Navigations
- πΎ Applying the Migration
- π BuildTargetModel Deep Dive
- π Sample Code Blocks & Usage Examples
- π EntityβRelationship (ER) Diagram (PlantUML)
- π 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 ondotnet 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
irbyby 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
- Add Migration
dotnet ef migrations add AddBillingTable - Update Database
dotnet ef database update - Verify
- Check that the
irby.BillingInvoicetable exists with all defined columns. - Confirm no breaking changes in other tables.
- Check that the
β οΈ The
.Designer.csfile 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! π