📚 Migrations Documentation:
IrbyImaging.DbContext/Migrations/20240320155820_UpdateLegalDashDBtables3.Designer.cs
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Migration: UpdateLegalDashDBtables3
- BuildTargetModel Method
- Data Models by Domain
- Relationships & Navigation Properties
- Applying & Rolling Back
- Usage Examples
- UML Class Diagram (Excerpt)
- Conclusion
1. Overview & Purpose
UpdateLegalDashDBtables3.Designer.cs is the EF Core–generated snapshot of the target model for the 20240320155820_UpdateLegalDashDBtables3 migration. It lives under the IrbyImaging.DbContext.Migrations namespace and provides a point-in-time definition of your database model so that EF Core can compute schema diffs, generate SQL, and apply or roll back migrations.
- 📌 Auto‑Generated
- ⚙️ Implements
BuildTargetModel(ModelBuilder modelBuilder) - 🎯 Goal: Capture every table, column, key, index, relationship, and discriminator mapping
2. Dependencies & Technologies
| Technology | Version | Purpose |
|---|---|---|
| Microsoft.EntityFrameworkCore | 7.0.7 | ORM / Migrations |
| Microsoft.EntityFrameworkCore.SqlServer | 7.0.7 | SQL Server provider |
| .NET 7 | 7.x | Target framework |
3. Key Functional Areas
- Schema Snapshot: Defines all tables (
ToTable), columns (Property), keys (HasKey), and indexes (HasIndex). - Inheritance Mapping: Uses TPH (Table‐Per‐Hierarchy) via
.HasDiscriminatorforAssetsubtypes (Computer,MobileDevice, etc.). - Relationships: Sets up foreign keys and navigation (
HasOne,WithMany). - Value Generation: Configures identity columns and default GUID generation.
- Annotations: Schema-level metadata (
ProductVersion,MaxIdentifierLength).
4. Migration: UpdateLegalDashDBtables3
[DbContext(typeof(IrbyContext))]
[Migration("20240320155820_UpdateLegalDashDBtables3")]
partial class UpdateLegalDashDBtables3 : Migration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// ... auto‐generated code ...
}
}
- Namespace:
IrbyImaging.DbContext.Migrations - Class:
UpdateLegalDashDBtables3 - Purpose: Capture the final model after applying this migration.
- Not intended for manual editing.
5. BuildTargetModel Method
This method configures the ModelBuilder to exactly reflect your DbContext’s domain classes at this migration point:
- Global Annotations
modelBuilder .HasAnnotation("ProductVersion", "7.0.7") .HasAnnotation("Relational:MaxIdentifierLength", 128); - Identity Columns
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - Entity Configuration
modelBuilder.Entity("FullTypeName", b => { ... })- Defines Properties, Keys, Indexes, Discriminator for TPH.
6. Data Models by Domain
Below is an organized view of the 70+ entities created or updated by this migration.
6.1 Asset Management 🚚
| Entity | Table | Key | Notes |
|---|---|---|---|
| Asset | irby.Asset | Id (GUID) | Base class |
| AssetHistory | irby.AssetHistory | Id (GUID) | Audit trail |
| AssetModel | irby.AssetModel | Id (int) | Tied to Manufacturer |
| AssetModelDetail | AssetModelDetail | Id (int) | Additional specs |
| Manufacturer | irby.AssetManufacturer | Id (int) | Makes / Brands |
| OperatingSystem | irby.OperatingSystem | Id (int) | OS look‑up |
6.2 Audit & Logging 🔍
| Entity | Table | Key |
|---|---|---|
| AuditDetail | irby.AuditDetail | AuditDetailId |
| AuditReport | AuditReport | No PK |
6.3 Document Management 📄
| Entity | Table | Key | Schema |
|---|---|---|---|
| DocumentCategory | irby.DocumentCategory | Id (GUID) | irby |
| DocumentType | irby.DocumentType | Id (GUID) | irby |
| DocumentAttribute | irby.DocumentAttribute | Id (GUID) | irby |
| DocumentImage | irby.DocumentImage | DocumentImageId | irby |
| TempDocumentData | irby.TempDocumentData | TempDocumentDataId | irby |
| BlobData | irby.BlobData | BlobDataId | irby |
6.4 Financial & Billing 💰
| Entity | Table | Key |
|---|---|---|
| BillingInvoice | irby.BillingInvoice | Id (GUID) |
| GeneralLedger | irby.GeneralLedger | Id (GUID) |
| GLTypeDetail | GLTypeDetail | Id (GUID) |
| CarrierType | irby.CarrierType | Id (GUID) |
| CarrierTypeDetail | CarrierTypeDetail | Id (GUID) |
6.5 Human Resources 👥
| Entity | Table | Key |
|---|---|---|
| Employee | irby.Employee | EmployeeId |
| Department | irby.Department | DepartmentId |
| Role | irby.Role | RoleId |
| Permissions | irby.Permissions | PermissionId |
| LinkUserRole | irby.LinkUserRole | Id |
| LinkRolePermission | irby.LinkRolePermission | Id |
6.6 Job & Field Office 🏗️
| Entity | Table | Key |
|---|---|---|
| Job | irby.Job | JobId |
| FieldOffice | irby.FieldOffice | Id |
| JobAndFieldOfficeMapping | JobAndFieldOfficeMapping | No PK |
6.7 ODS (Operational Data Store) 🗄️
| Entity | Table | Key | Source |
|---|---|---|---|
| ODSCustomer | ODSCustom ers | No PK | External DB Sync |
| ODSEmployee | ODSEmployees | No PK | External DB Sync |
| ODSJob | ODSJobs | No PK | External DB Sync |
6.8 Auxiliary & Lookup Entities 🔧
| Entity | Table | Key |
|---|---|---|
| Customer | irby.Customer | Id |
| State | irby.State | Id |
| StatePropertyCosts | irby.StatePropertyCosts | Id |
| RequestOption | irby.RequestOption | Id |
| TimeEntryType | TimeEntryType | TimeEntryTypeId |
| TimeSheetEntry | irby.TimeSheetEntry | TimeSheetEntryId |
6.9 Asset Inheritance Hierarchy 🌳
All assets share a single table irby.Asset with a discriminator column
Asset (base)
├─ Computer
├─ DeskPhone
├─ Dock
├─ MobileDevice
├─ Monitor
├─ NetworkEquipment
├─ OfficePrinter
├─ Printer
├─ SafetyEquipment
| Derived Type | Discriminator Value | Extra Columns |
|---|---|---|
| Computer | "Computer" | AssetNumber, CpsNumber, OperatingSystemId |
| MobileDevice | "MobileDevice" | Imei (unique), Sim, PhoneNumber, Carrier |
| OfficePrinter | "OfficePrinter" | Company, ContractEndDate |
| SafetyEquipment | "SafetyEquipment" | AssetNumber, CpsNumber, OperatingSystemId |
| … | … | … |
7. Relationships & Navigation Properties
-
Asset → AssetModel (
ModelId) -
Asset → FieldOffice (
FieldOfficeId) -
Asset → Employee (Owner) (
OwnerId) -
Employee → Department (
DepartmentId) -
Employee → Job (
JobId) -
Job → FieldOffice (
FieldOfficeId) -
AuditDetail → Employee (User) (
EmployeeId) -
AuditDetail → Role (
RoleId) -
LinkUserRole → Employee, Role
-
LinkRolePermission → Role, Permissions
-
TimeSheetEntry → Employee, TimeEntryType
All FKs use OnDelete(DeleteBehavior.Cascade) where required.
8. Applying & Rolling Back
- Add Migration
dotnet ef migrations add UpdateLegalDashDBtables3 - Apply Migration
dotnet ef database update - Rollback
dotnet ef database update 20240320150000_PreviousMigration
9. Usage Examples
Query all Assets with Owner & Model
var assets = await context.Assets
.Include(a => a.Owner)
.Include(a => a.Model)
.ToListAsync();
Create a New DocumentImage
var doc = new DocumentImage
{
DocumentImageId = Guid.NewGuid(),
FileName = "Contract.pdf",
ContentType = "application/pdf",
DocumentUploadedBy = userEmail,
DocumentUploadedDate= DateTime.UtcNow,
ImagingType = 2, // e.g. Legal
IsLegalDocument = true
};
context.DocumentImages.Add(doc);
await context.SaveChangesAsync();
10. UML Class Diagram (Excerpt)
+----------------+ +------------------+ +---------------+
| Asset |<>---------| AssetModel | | Manufacturer |
+----------------+ +------------------+ +---------------+
| Id : Guid | | Id : int | 1 * | Id : int |
| Category | | Name : string |---------| Name : string |
| SerialNumber | | MakeId : int | | WarrantyMonths|
| Discriminator | +------------------+ +---------------+
+----------------+
+-------------+ +------------+
| Employee |<>-----<| Department |
+-------------+ +------------+
| EmployeeId | | DepartmentId|
| FirstName | | Name |
| LastName | +-------------+
+-------------+
11. Conclusion
This auto‑generated _Designer.cs file serves as a snapshot of your EF Core model at the point of the UpdateLegalDashDBtables3 migration. It ensures that migrations remain deterministic and that schema changes can be computed reliably by the EF Core tooling.
✨ Tip: Do not manually edit this file—any required changes should be made upstream in your domain classes or in the
Up()/Down()methods of the corresponding.csmigration.
Happy Coding! 🛠️🚀