📚 IrbyImaging.DbContext.Migrations
20220303153431_UpdateFileName.Designer.cs Documentation
📋 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models & Mappings
- Entity Relationship Diagram (UML)
- Usage & Examples
- Conclusion
1. Overview & Purpose
🎯 What is this file?
- This is the auto‑generated EF Core migration “Designer” file for the migration named
20220303153431_UpdateFileName. - It defines the target snapshot of your database schema after the migration is applied.
📖 Why it matters:
- EF Core uses this file at runtime to determine how your model should look after all migrations up to this point.
- It is not hand‑modified; any schema changes (e.g., renaming a
FileNamecolumn) are declared in the associated.csmigration file, and this Designer file is produced by EF Core tools.
2. Dependencies & Technologies
| Technology / Package | Version / Description |
|---|---|
| Microsoft.EntityFrameworkCore | ORM framework for .NET |
| Microsoft.EntityFrameworkCore.Infrastructure | Core infrastructure abstractions |
| Microsoft.EntityFrameworkCore.Metadata | Metadata APIs (ModelBuilder, Annotations) |
| Microsoft.EntityFrameworkCore.Migrations | Migration APIs (Migration base class) |
| Microsoft.EntityFrameworkCore.Storage.ValueConversion | Value converters for database types |
| .NET 5.0 (Target Framework) | Project targets .NET 5.0 |
| SQL Server | Relational database (Identity columns) |
Tip:
The annotation.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn)instructs EF Core to use IDENTITY columns for integer primary keys in SQL Server.
3. Key Functional Areas
- Model Snapshot (
BuildTargetModel)- Defines all entities, properties, keys, indexes, relationships, and table mappings.
- Discriminator & Inheritance
- Single-table inheritance for
Assetand its sub‑classes (e.g.,Computer,MobileDevice). - Uses a Discriminator column to distinguish derived types.
- Single-table inheritance for
- Schema Organization
- Most tables live in the
irbyschema. - Staging tables (
ODS_Employee_Staging,ODS_Jobs_Staging) live in the same schema.
- Most tables live in the
- Indexing & Constraints
- Unique indexes on business keys (e.g.,
JdeNumber,Imei). - Foreign keys enforce referential integrity.
- Unique indexes on business keys (e.g.,
- Timestamps & Auditing
- Many entities have audit fields (
AddedDate,ModifiedDate,AddedBy,ModifiedBy).
- Many entities have audit fields (
4. Data Models & Mappings
Below is a selection of the most important entities to illustrate the scope of the model:
| Entity | Table (schema) |
Primary Key | Description |
|---|---|---|---|
| Asset | irby.Asset |
Id (GUID) |
Base asset class (serial number, status, owner) |
| Computer | inherits Asset |
Id (GUID) |
Asset subtype – adds OperatingSystemId, etc. |
| MobileDevice | inherits Asset |
Id (GUID) |
Asset subtype – IMEI, phone number, carrier |
| AssetHistory | irby.AssetHistory |
Id (GUID) |
Tracks changes on assets (status, owner, notes) |
| AssetModel | irby.AssetModel |
Id (int) |
Model definitions – Name, Category, Make, Type |
| Manufacturer | irby.AssetManufacturer |
Id (int) |
Manufacturers of assets (warranty info) |
| Employee | irby.Employee |
Id (GUID) |
Company employees, with unique JdeNumber |
| FieldOffice | irby.FieldOffice |
Id (GUID) |
Offices linked to employees and assets |
| Job | irby.Job |
Id (GUID) |
Project or job code with unique JdeNumber |
| DocumentImage | irby.DocumentImage |
DocumentImageId |
Stores image content & OCR text for documents |
| TempDocumentData | irby.TempDocumentData |
TempDocumentDataId |
Staging table for document migration |
| IPMMigration | irby.IPMMigration |
IPMMigrationId |
Historical staging table for IPM migrations |
| COVIDTestData | irby.CovidTestData |
CovidTestDataId |
COVID‐19 test records, images, results |
| ODS_Employee_Staging | irby.ODS_Employee_Staging |
EMPLOYEE_NUMBER |
Staging table (organizational data sync) |
| ODS_Jobs_Staging | irby.ODS_Jobs_Staging |
ORG_BU |
Staging table for job sync |
Note:
The discriminator column onirby.Assetdrives the single‐table inheritance. Entities likeComputerandMobileDeviceshare the same table but have their own specific columns.
5. Entity Relationship Diagram (UML)
Below is a simplified Mermaid class diagram showing core relationships.
Copy this into a Markdown preview supporting Mermaid diagrams (e.g., VS Code with Markdown Preview Mermaid Support).
classDiagram
%% Base Entities
Asset <|-- Computer
Asset <|-- DeskPhone
Asset <|-- Dock
Asset <|-- MobileDevice
Asset <|-- Monitor
Asset <|-- NetworkEquipment
Asset <|-- OfficePrinter
Asset <|-- Printer
Asset <|-- SafetyEquipment
Asset o-- AssetModel : ModelId
AssetModel o-- Manufacturer : MakeId
Asset o-- FieldOffice : FieldOfficeId
Asset o-- Employee : OwnerId
Employee o-- Job : CurrentJobId
FieldOffice o-- Employee : ManagerId
GLTypeDetail o-- GeneralLedger : GeneralLedgerId
CarrierTypeDetail o-- CarrierType : CarrierTypeId
ODSEmployee o-- ODSJob : ORG_BU
6. Usage & Examples
6.1 Applying the Migration
Use the EF Core CLI or Package Manager Console:
# Add the migration (already exists)
dotnet ef migrations add UpdateFileName
# Update database to latest migration
dotnet ef database update
6.2 Inspecting a Specific Entity
using(var ctx = new IrbyContext())
{
// Fetch a document image by its FileName
var doc = ctx.DocumentImages
.FirstOrDefault(d => d.FileName == "Report.pdf");
Console.WriteLine($"Uploaded by {doc.DocumentUploadedBy} on {doc.DocumentUploadedDate}");
}
6.3 Renaming a Column Example
If your migration UpdateFileName actually renamed the FileName column:
// In 20220303153431_UpdateFileName.cs (Up method)
migrationBuilder.RenameColumn(
name: "OldFileName",
table: "DocumentImage",
newName: "FileName");
After scaffolding, the Designer file (BuildTargetModel) will reflect:
b.Property<string>("FileName").HasColumnType("nvarchar(max)");
7. Conclusion
🚀 What did we learn?
- This Designer file is the model snapshot for the
UpdateFileNamemigration. - It captures the entire database schema at this point in time—all entities, keys, indexes, relationships, and inheritance mapping.
- It is central to EF Core’s ability to apply and rollback migrations reliably.
🛠 Next steps:
- Do not manually modify this file.
- To introduce schema changes, create or update your migration classes (
.cs) and let EF Core regenerate the Designer automatically. - Use the CLI or PMC commands to keep your database in sync with your C# model.
Happy coding! 🎉