π¦ IrbyImaging.DbContext/Migrations/20220809153958_UpdateDocImageTable.Designer.cs Documentation
File Path
IrbyImaging.DbContext/Migrations/20220809153958_UpdateDocImageTable.Designer.cs
Generated by
Entity Framework Core (5.0.12)
Purpose
Captures the target model snapshot for theUpdateDocImageTablemigration, used by EF Core to build and compare the database schema.
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- BuildTargetModel Method
- Entity Models & Data Schema
- Key Functional Areas
- Entity Configuration Examples
- Relationships & Associations
- Inheritance & Discriminator Mapping
- Usage & Execution
- UML Diagram (Mermaid)
- Additional Sections
- Conclusion
1. Overview & Purpose π
This Designer file is an auto-generated snapshot of your EF Core model at the point in time of the migration named 20220809153958_UpdateDocImageTable. It contains:
- The
BuildTargetModel(ModelBuilder modelBuilder)method - Entity definitions (tables, columns, PKs, FKs, indexes)
- Inheritance (TPH via discriminators)
β Note:
You should not manually edit this file.
EF Core will overwrite it when you add or remove migrations.
2. Dependencies & Technologies π
| Component | Version / Type |
|---|---|
| .NET | 5.0 |
| C# | 9.0 |
| Entity Framework Core | 5.0.12 |
| Database Provider | Microsoft.EntityFrameworkCore.SqlServer |
| EF Core Tools | dotnet ef CLI |
Key Namespaces:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
3. BuildTargetModel Method π§
At the heart of this file lies:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.12")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// ... hundreds of .Entity(...) calls for each domain class
#pragma warning restore 612, 618
}
- Purpose: Defines how each CLR class maps to a database table.
- Annotations:
MaxIdentifierLengthsets max length of SQL identifiers.ProductVersionrecords EF Core version.ValueGenerationStrategyconfigures identity columns.
4. Entity Models & Data Schema π
This migration snapshot covers 40+ entities. They can be grouped by business area:
| Domain Area | Entities |
|---|---|
| Asset Management | Asset, AssetHistory, AssetModel, AssetModelDetail, Manufacturer, OperatingSystem, Computer, DeskPhone, Dock, MobileDevice, Monitor, NetworkEquipment, OfficePrinter, Printer, SafetyEquipment |
| Document Handling | DocumentImage, DocumentType, DocumentCategory, DocumentAttribute, TempDocumentData, IPMMigration, IrbyForms |
| Human Resources | Employee, ODS_Employee_Staging, ODS_Jobs_Staging, FieldOffice, Job |
| Billing & GL | BillingInvoice, CarrierType, CarrierTypeDetail, GeneralLedger, GLTypeDetail |
| Ticketing System | Ticket, Update |
| Compliance & Other | CovidTestData, Issue, RequestOption, State |
5. Key Functional Areas π
-
Schema Definition
- Tables, columns, data types
- Primary keys & foreign keys
- Indexes & unique constraints
-
Inheritance & TPH Discriminators
- Asset hierarchy (
Computer,MobileDevice, etc.) - Uses
Discriminatorcolumn on table"Asset","irby"
- Asset hierarchy (
-
Navigation Properties
- One-to-many, many-to-one relationships
- Cascade delete behaviors
-
Migrations Support
- Snapshot used to generate
Up()/Down()SQL - EF Core CLI orchestration
- Snapshot used to generate
6. Entity Configuration Examples π
6.1 DocumentImage
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
b.ToTable("DocumentImage","irby");
b.HasKey("DocumentImageId").HasName("PrimaryKey_DocumentImageId");
b.Property<Guid>("DocumentImageId").HasColumnType("uniqueidentifier");
b.Property<byte[]>("ImageContents").HasColumnType("varbinary(max)");
b.Property<string>("DocumentType").HasColumnType("nvarchar(max)");
b.Property<bool>("IsLegalDocument").HasColumnType("bit");
// β¦ other properties β¦
// No direct FKs; reference via DocumentType or Category name fields
});
6.2 Asset (TPH + Discriminator)
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
b.ToTable("Asset", "irby");
b.HasKey("Id");
b.Property<Guid>("Id").ValueGeneratedOnAdd();
b.Property<string>("Discriminator")
.IsRequired()
.HasColumnType("nvarchar(max)");
// Base properties
b.Property<string>("SerialNumber").HasColumnType("nvarchar(max)");
// β¦
// TPH Inheritance
b.HasDiscriminator<string>("Discriminator")
.HasValue("Asset");
});
6.3 Asset β Computer Subclass
modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b =>
{
b.HasBaseType("IrbyImaging.DomainClasses.Asset");
b.Property<int>("OperatingSystemId")
.HasColumnType("int");
b.HasIndex("OperatingSystemId");
b.ToTable("Asset","irby");
b.HasDiscriminator().HasValue("Computer");
// Relationship
b.HasOne("IrbyImaging.DomainClasses.OperatingSystem", "OperatingSystem")
.WithMany()
.HasForeignKey("OperatingSystemId")
.OnDelete(DeleteBehavior.Cascade);
});
7. Relationships & Associations π
-
One-toβMany
AssetModelβAssetModelDetailFieldOfficeβAssetTicketβUpdateJobβEmployee
-
Many-toβOne
AssetβAssetModelAssetβEmployee(Owner)
-
Cascade Deletes
- Removing a
Jobwill remove itsEmployees. - Deleting an
OperatingSystemcascadeβdeletes itsComputerassets.
- Removing a
8. Inheritance & Discriminator Mapping π·οΈ
All deviceβtype classes inherit from the Asset base:
classDiagram
class Asset {
+Guid Id
+string Discriminator
+string SerialNumber
+...
}
class Computer
class MobileDevice
class DeskPhone
class Monitor
Asset <|-- Computer
Asset <|-- MobileDevice
Asset <|-- DeskPhone
Asset <|-- Monitor
- Single Table Inheritance (TPH)
- Discriminator Column:
"Discriminator" - Values:
"Computer","MobileDevice","DeskPhone", etc.
9. Usage & Execution π
Generating a Migration
dotnet ef migrations add UpdateDocImageTable
- Creates two files:
20220809153958_UpdateDocImageTable.cs20220809153958_UpdateDocImageTable.Designer.cs(this file)
Applying to Database
using (var context = new IrbyContext())
{
context.Database.Migrate();
}
- EF Core uses the Designer snapshot to decide what SQL to run.
10. UML Diagram (Mermaid) π
Below is a simplified class diagram for the Document domain:
classDiagram
class DocumentImage {
+Guid DocumentImageId
+byte[] ImageContents
+string DocumentType
+bool IsLegalDocument
+int Page
+int TotalPages
}
class DocumentType {
+Guid Id
+string Type
+string DocumentCategory
}
class DocumentCategory {
+Guid Id
+string Name
+string Description
}
DocumentImage --> DocumentType : uses
DocumentType --> DocumentCategory : categorizes
11. Additional Sections π
View Models & Data Models
- Data Models: All EF Core entity classes in the
modelBuilder.Entity(...)calls. - View Models: N/A (not part of migration snapshot).
Helper Methods / Utilities
- BuildTargetModel: Central method; no additional helpers.
Error Handling and Return Types
- Not applicable; this file simply describes the schema.
API Endpoints Overview
- Not applicable; data access layer only.
Third-party Integrations
- Only EF Core and SQL Server provider.
12. Conclusion β
This Designer migration file is your schema snapshot for EF Core. It ensures consistency between your domain classes and the database.
- Do not edit it manually.
- When you add, remove, or rename entities/properties, always generate a new migration.
- Use
dotnet efcommands orcontext.Database.Migrate()to keep your database in sync.
Happy coding! π