📦 Migration File Documentation
File: IrbyImaging.DbContext/Migrations/20230131220319_LytxTemplate.Designer.cs
Generated By: Entity Framework Core 5.0.12
Purpose: Defines the target database model for the LytxTemplate migration, capturing tables, columns, keys, indexes and relationships.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Entity & Data Models
- Relationships & Navigation Properties
- How It Works
- Sample Code Blocks
- UML Class Diagram (Excerpt)
- Usage & Application
- Conclusion
1. Overview & Purpose
🛠️ This .Designer.cs file is auto‑generated by Entity Framework Core when you add a migration named "LytxTemplate". It contains the BuildTargetModel method that:
- Defines all entity types (tables) with their columns, data types, constraints, indexes and keys.
- Configures inheritance (discriminators) for the
Assethierarchy. - Registers relationships (foreign keys) and navigation properties.
- Captures EF Core‐specific annotations such as SQL Server’s identity strategy.
Why it matters:
When you rundotnet ef database update, EF Core compares the migration snapshot (this file) against the current database and applies any schema changes needed to bring the database into this state.
2. Dependencies & Technologies
| Component | Version | Purpose |
|---|---|---|
| Microsoft.EntityFrameworkCore | 5.0.12 | Core ORM framework |
| Microsoft.EntityFrameworkCore.Infrastructure | 5.0.12 | Infrastructure services |
| Microsoft.EntityFrameworkCore.Metadata | 5.0.12 | Metadata APIs |
| Microsoft.EntityFrameworkCore.Migrations | 5.0.12 | Migration builder & runner |
| Microsoft.EntityFrameworkCore.Storage.ValueConversion | 5.0.12 | Value converter support |
| .NET / C# | >= .NET Core 3.1 | Language & runtime |
3. Key Functional Areas
- Model Snapshot
Captures the entire domain model in code so EF Core can calculate diffs. - Entity Configuration
- Properties (
HasColumnType,IsRequired,ValueGeneratedOnAdd, etc.) - Table & schema mapping (
ToTable("X", "irby")) - Keys & indexes (
HasKey,HasIndex)
- Properties (
- Inheritance via Discriminator
All asset‐related subclasses (Computer,DeskPhone,MobileDevice, etc.) share theAssettable using a Discriminator column. - Relationship Configuration
Defines foreign keys and cascading behaviors, e.g.Asset.ModelId → AssetModel.Id(cascade delete)Employee.CurrentJobId → Job.IdUpdate.TicketId → Ticket.Id
4. Entity & Data Models
Below is a representative subset of the 40+ entities defined in this migration.
| Entity Class | Table (Schema) | Primary Key | Description |
|---|---|---|---|
| Asset | Asset (irby) |
Id (GUID) |
Base class for all tangible assets. Includes Category, Status, SerialNumber, etc. |
| Computer | (Discriminator: Computer) |
inherits Asset.Id |
Asset subclass; adds AssetNumber, OperatingSystemId, UnitNumber. |
| MobileDevice | (Discriminator: MobileDevice) |
inherits Asset.Id |
Adds Imei (unique), PhoneNumber, Carrier, etc. |
| AssetModel | AssetModel (irby) |
Id (int) |
Defines model types. FK → Manufacturer |
| AssetHistory | AssetHistory (irby) |
Id (GUID) |
Audit log for asset changes. |
| Employee | Employee (irby) |
Id (GUID)JdeNumber unique |
Company employees, FK → Job (CurrentJob). |
| FieldOffice | FieldOffice (irby) |
Id (GUID) |
Regional offices. FKs to various Employee as managers. |
| Job | Job (irby) |
Id (GUID)JdeNumber unique |
Projects or jobs. |
| Ticket | Ticket (irby) |
Id (GUID) |
Support request, with status, type, images, JSON payloads. |
| Update | Update (irby) |
Id (GUID) |
Comments/history of Ticket. |
| DocumentImage | DocumentImage (irby) |
DocumentImageId (GUID) |
Stores scanned document bytes + OCR. |
| CovidTestData | CovidTestData (irby) |
CovidTestDataId (GUID) |
Employee COVID test results. |
| … | … | … | … |
🔎 Tip: You can find all other entities (e.g.
CarrierType,BillingInvoice,GLTypeDetail,ODS_Employee, etc.) by searching withinBuildTargetModelin the code.
5. Relationships & Navigation Properties
The migration configures foreign keys and navigations such as:
- Asset ↔ FieldOffice
- Asset ↔ AssetModel
- Asset ↔ Employee (Owner)
- AssetModel ↔ Manufacturer
- Employee ↔ Job (CurrentJob)
- FieldOffice ↔ Employee (Manager, ProjectManager, Superintendent)
- GLTypeDetail ↔ GeneralLedger
- ODS_Employee ↔ ODS_Jobs_Staging
- Update ↔ Ticket
- Computer,SafetyEquipment ↔ OperatingSystem
Example:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
b.HasOne("IrbyImaging.DomainClasses.AssetModel", "Model")
.WithMany()
.HasForeignKey("ModelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IrbyImaging.DomainClasses.Employee", "Owner")
.WithMany("Assets")
.HasForeignKey("OwnerId");
// …other FKs…
});
6. How It Works
- Design-Time Snapshot
EF Core stores this snapshot in the migration’s.Designer.csso it “knows” the exact model shape at the time of migration creation. - BuildTargetModel
Invoked by EF Core tools to reconstruct the model. - Diff Calculation
When you later add another migration, EF Core compares your currentDbContextmodel to this snapshot to generate the next migration. - Database Update
RunningUpdate-Databasereads this model to apply DDL to your database.
7. Sample Code Blocks
Model Annotations & Global Strategy
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.12")
.HasAnnotation("SqlServer:ValueGenerationStrategy",
SqlServerValueGenerationStrategy.IdentityColumn);
Defining an Entity & Discriminator
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("nvarchar(max)");
// … other properties …
b.HasKey("Id");
b.ToTable("Asset", "irby");
// Inheritance discriminator
b.HasDiscriminator<string>("Discriminator")
.HasValue("Asset");
});
Subclass Mapping (Computer)
modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b =>
{
b.HasBaseType("IrbyImaging.DomainClasses.Asset");
b.Property<string>("AssetNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("OperatingSystemId")
.HasColumnType("int");
b.HasIndex("OperatingSystemId");
b.ToTable("Asset", "irby");
b.HasDiscriminator().HasValue("Computer");
});
8. UML Class Diagram (Excerpt)
@startuml
class Asset {
+Guid Id
+string Category
+string SerialNumber
+DateTimeOffset PurchaseDate
+string Status
+string Discriminator
}
class Computer {
+string AssetNumber
+int OperatingSystemId
+string UnitNumber
}
class MobileDevice {
+string Imei
+string PhoneNumber
+string Carrier
+bool IsTelogis
}
Asset <|-- Computer
Asset <|-- MobileDevice
@enduml
📊 Note: This is a partial UML focusing on the
Assetinheritance hierarchy.
9. Usage & Application
- Generating the Migration:
dotnet ef migrations add LytxTemplate - Applying to Database:
dotnet ef database update - Inspecting Model:
You can read throughBuildTargetModelto verify table/column definitions, indexes, and relationships before applying.
🔗 Tip: Treat this file as a read‑only snapshot. All manual model tweaks belong in your
DbContextand entity classes.
10. Conclusion
This Designer file is a blueprint of your database schema at the point when the LytxTemplate migration was created. It is crucial for EF Core’s change‑tracking and migration generation.
- DO review it to understand table shapes and relationships.
- DON’T manually edit it—any changes should go into your entity classes or DbContext.OnModelCreating.
Happy coding! 🎉