📋 IrbyImaging.DbContext Migration
File: Migrations/20231003133244_ITDMS.Designer.cs
Table of Contents
- Overview & Purpose
- Migration Class & Method
- Key Functional Areas
- Dependencies & Technologies
- Data Models & Entity Mappings
- Indexes, Schemas & Key Constraints
- Discriminator & Inheritance (TPH)
- Relationships & Navigation Properties
- Sample Code Blocks & Snippets
- UML Class Diagram (Mermaid)
- Usage & Applying Migration
- Conclusion
1. Overview & Purpose 🎯
This file is an Entity Framework Core auto-generated migration snapshot. It captures the target database model (schema, tables, columns, relationships, indexes, etc.) for the IrbyContext.
- Name:
ITDMS - Timestamp:
2023‑10‑03T13:32:44 - Role: Defines how your .NET domain classes map onto SQL Server tables and columns.
- When to use:
- After running
dotnet ef migrations add ITDMS - To apply changes:
dotnet ef database update
- After running
2. Migration Class & Method 🛠️
[DbContext(typeof(IrbyContext))]
[Migration("20231003133244_ITDMS")]
partial class ITDMS
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// Configuration code …
}
}
DbContextAttribute: Associates this migration with theIrbyContext.MigrationAttribute: Timestamped identifier.BuildTargetModel: Core method wheremodelBuilderis used to define:- Annotations (
ProductVersion,Relational:MaxIdentifierLength) - Identity columns
- Entity configurations (tables, columns, primary keys, indexes, relationships)
- Annotations (
3. Key Functional Areas 🏗️
- Schema Configuration
- Table & Column Definitions
- Primary Keys & Indexes
- Inheritance Mapping (TPH – Table‑Per‑Hierarchy)
- Foreign Keys & Navigation
- Discriminator Columns
4. Dependencies & Technologies 🔌
| Package / Namespace | Purpose |
|---|---|
| Microsoft.EntityFrameworkCore | Core ORM framework |
| Microsoft.EntityFrameworkCore.Metadata | Metadata API for model building |
| Microsoft.EntityFrameworkCore.Migrations | Migrations support |
| Microsoft.EntityFrameworkCore.Storage.ValueConversion | Column conversions |
| SqlServerModelBuilderExtensions | SQL Server–specific identity column setup |
5. Data Models & Entity Mappings
Below is a thematic breakdown of the mapped domain classes and their target tables.
5.1 IT Asset Management 💻
| Domain Class | Table | Schema | Description |
|---|---|---|---|
| Asset | Asset | irby | Base class for all assets |
| Computer | Asset (TPH) | irby | Desktop/laptop specific properties |
| MobileDevice | Asset (TPH) | irby | Phone/tablet-specific properties |
| DeskPhone, Monitor, Printer, Dock, SafetyEquipment, NetworkEquipment, OfficePrinter | Asset (TPH) | irby | Other asset types |
Key Columns (Asset):
Id(PK, uniqueidentifier)Category(nvarchar)SerialNumberPurchaseDateStatus,NeedsReview,Notes- Foreign keys:
ModelId,FieldOfficeId,OwnerId
5.2 Document Management 📄
| Domain Class | Table | Schema | Description |
|---|---|---|---|
| DocumentImage | DocumentImage | irby | Stores scanned image & OCR data |
| DocumentType | DocumentType | irby | Types/categories of documents |
| DocumentCategory | DocumentCategory | irby | High‑level classifications |
| DocumentAttribute | DocumentAttribute | irby | Indexable attributes/fields |
| TempDocumentData | TempDocumentData | irby | Staging area before final indexing |
| BlobData | BlobData | irby | Raw binary blob storage |
5.3 Human Resources & Time Tracking 👥
| Domain Class | Table | Schema | Description |
|---|---|---|---|
| Employee | Employee | irby | Employee master data |
| Department | Department | irby | Dept. definitions |
| TimeEntryType | TimeEntryType | irby | Enum of entry types (e.g., Regular, Overtime) |
| TimeSheetEntry | TimeSheetEntry | irby | Daily time entries |
5.4 Finance & Billing 💰
| Domain Class | Table | Schema | Description |
|---|---|---|---|
| BillingInvoice | BillingInvoice | irby | Invoices charged to carriers/customers |
| CarrierType | CarrierType | irby | Carrier master list |
| CarrierTypeDetail | CarrierTypeDetail | irby | Carrier sub‑types |
| GeneralLedger | GeneralLedger | irby | Chart of accounts |
| GLTypeDetail | GLTypeDetail | irby | Sub‑ledger details |
5.5 Audit & Security 🔒
| Domain Class | Table | Schema | Description |
|---|---|---|---|
| AuditDetail | AuditDetail | irby | Tracks user/controller actions |
| Role | Role | irby | Security roles |
| Permissions | Permissions | irby | Fine‑grained permissions |
| LinkUserRole | LinkUserRole | irby | Many‑to‑many Employee ↔ Role |
| LinkRolePermission | LinkRolePermission | irby | Many‑to‑many Role ↔ Permissions |
5.6 External Data Sync (ODS) 🏭
| Domain Class | Table | Schema | Description |
|---|---|---|---|
| ODSCustomer | ODSCustomers | dbo¹ | Imported customer data from ERP |
| ODSEmployee | ODSEmployees | dbo¹ | Imported employee data from ERP |
| ODSJob | ODSJobs | dbo¹ | Imported job/project data from ERP |
¹ These often live in the default schema (no "irby" prefix).
6. Indexes, Schemas & Key Constraints 🔑
- Schemas: Most tables are in
"irby"schema. ODS tables use default. - Primary Keys: Defined via
.HasKey("…"). - Indexes:
.HasIndex(…)for FK and unique constraints.- e.g.
Employee.JdeNumberis unique if not null. FieldOffice.JdeNumberunique.MobileDevice.Imeiunique.
- e.g.
7. Discriminator & Inheritance (TPH) 🌳
Table‑Per‑Hierarchy (TPH) is used for the Asset hierarchy:
- A single
Assettable holds all subtypes. - A
Discriminatorcolumn (nvarchar(max)) indicates the subtype. - Example:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset") .HasDiscriminator<string>("Discriminator") .HasValue("Asset") .UseTphMappingStrategy(); - Subclasses override the discriminator:
b.HasDiscriminator().HasValue("Computer"); b.HasDiscriminator().HasValue("MobileDevice"); // …etc.
8. Relationships & Navigation Properties 🔄
- One‑to‑Many:
FieldOffice→AssetsAssetModel→AssetsModelDetailManufacturer→ModelsJob→EmployeesTicket→Updates
- Many‑to‑Many via link tables:
Employee↔Role(LinkUserRole)Role↔Permissions(LinkRolePermission)
- Cascade Deletes where appropriate:
AssetModeldelete cascades onAssetJobdelete cascades onEmployee
9. Sample Code Blocks & Snippets
9.1 Configuring a Simple Entity
modelBuilder.Entity("IrbyImaging.DomainClasses.CarrierType", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Carrier")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsInactive")
.HasColumnType("bit");
b.HasKey("Id");
b.ToTable("CarrierType", "irby");
});
9.2 Defining an Index & Constraints
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
b.HasIndex("JdeNumber")
.IsUnique()
.HasFilter("[JdeNumber] IS NOT NULL");
});
10. UML Class Diagram (Mermaid) 🌐
classDiagram
%% Inheritance (TPH)
Asset <|-- Computer
Asset <|-- MobileDevice
Asset <|-- DeskPhone
Asset <|-- Monitor
Asset <|-- Printer
Asset <|-- SafetyEquipment
%% Core Entities
Asset : Guid Id
Asset : string Category
Asset : int ModelId
Asset : DateTimeOffset PurchaseDate
Asset : string Status
AssetModel : int Id
AssetModel : string Name
FieldOffice : Guid Id
FieldOffice : string Name
Employee : Guid EmployeeId
Employee : string FirstName
Employee : string LastName
%% Relationships
Asset --> AssetModel : ModelId
Asset --> FieldOffice : FieldOfficeId
Asset --> Employee : OwnerId
AssetModel --> Manufacturer : MakeId
11. Usage & Applying Migration 🚀
- Add Migration
dotnet ef migrations add ITDMS - Update Database
dotnet ef database update - Inspect the generated snapshot (
Designer.cs) to verify schema. - Commit both
ITDMS.cs(Up/Down methods) andITDMS.Designer.csto source control.
12. Conclusion 🏁
This designer file is the snapshot of your domain model at migration time. It ensures that Entity Framework Core knows exactly how to build, validate, and migrate your SQL Server schema for the IrbyContext.
- Do not manually edit this file—it's regenerated on each migration.
- Use it to track schema changes, debug mapping issues, and guarantee consistent database evolution across environments.
- Pair it with the
Up()/Down()methods inITDMS.csto fully define migration steps.
Happy coding & database evolving! 🚀