ποΈ Table of Contents
- Overview & Purpose
- File Structure & Context
- Dependencies & Technologies
- Key Components
4.1 BuildTargetModel Method
4.2 ModelBuilder Configuration
4.3 Entity & Table Mappings
4.4 Relationships & Navigation Properties
- Functional Areas & Domain Model
5.1 Asset Management Entities
5.2 Document Management Entities
5.3 Job & Field Office Entities
5.4 Accounting & Billing Entities
5.5 Ticketing System Entities
5.6 Data Migration & Staging Entities
5.7 Integration & Staging Entities
5.8 Miscellaneous Entities
- Sample Code Snippets
- UML/ER Diagram (Conceptual)
- Usage & Best Practices
- Conclusion
π Overview & Purpose
IrbyImaging.DbContext/Migrations/20221103025954_DeleteNewColumnDocumentImageTable.Designer.cs is an auto-generated EF Core migration designer file. It captures the target database schema after applying the migration named DeleteNewColumnDocumentImageTable.
- Primary Goal: Define how all domain entities map to SQL Server tables, columns, keys, indexes, and relationships in the
"irby" schema.
- Not Editable: This file is regenerated whenever you scaffold migrations (
Add-Migration). Manual edits are overwritten.
- Context: Applies to the
IrbyContext DbContext, targeting EF Core 5.0.12 with SQL Server as the database provider.
π File Structure & Context
IrbyImaging.DbContext/
βββ Migrations/
βββ 20221103025954_DeleteNewColumnDocumentImageTable.cs
βββ 20221103025954_DeleteNewColumnDocumentImageTable.Designer.cs β (this file)
.Designer.cs: Contains the BuildTargetModel(ModelBuilder modelBuilder) method.
- Counterpart
.cs: Includes the Up() and Down() methods (schema changes).
π οΈ Dependencies & Technologies
| Category |
Details |
| ORM |
Entity Framework Core (EF Core 5.0.12) |
| Database Provider |
Microsoft SQL Server |
| Language |
C# (.NET 5.0) |
| Main API Surface |
Microsoft.EntityFrameworkCore |
| Value Conversion |
Microsoft.EntityFrameworkCore.Storage.ValueConversion |
π Key Components
4.1 BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// Disable warnings for obsolete methods
#pragma warning disable 612, 618
// Apply global annotations
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.12")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// [Entity definitions follow...]
#pragma warning restore 612, 618
}
- Purpose: Programmatically reconstruct the final EF Core model snapshot.
- Called By: EF Core tooling during
Update-Database or runtime model validation.
4.2 ModelBuilder Configuration
- Max Identifier Length:
128 characters (SQL Server limit).
- Product Version: Tracks EF Core version (
5.0.12).
- Value Generation Strategy: SQL Server
IDENTITY for auto-increment keys.
4.3 Entity & Table Mappings
For each domain class, EF Core generates:
- Table Schema: Usually
"irby".
- Column Mappings: C# type β SQL type (e.g.,
Guid β uniqueidentifier).
- Primary Keys:
.HasKey(...).
- Indexes:
.HasIndex(...), some unique.
- Discriminators: For inheritance (
Asset base and its derived types).
Example: Asset Entity
| CLR Property |
SQL Column |
Type |
Nullable |
Notes |
Id |
Id |
uniqueidentifier |
No |
PK, default (newid()) |
Category |
Category |
nvarchar(max) |
No |
|
FieldOfficeId |
FieldOfficeId |
uniqueidentifier |
Yes |
FK β FieldOffice.Id |
ModelId |
ModelId |
int |
No |
FK β AssetModel.Id |
Discriminator |
Discriminator |
nvarchar(max) |
No |
EF Core inheritance marker |
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("nvarchar(max)");
// ...
b.HasKey("Id");
b.HasIndex("FieldOfficeId");
b.HasIndex("ModelId");
b.ToTable("Asset", "irby");
b.HasDiscriminator<string>("Discriminator").HasValue("Asset");
});
4.4 Relationships & Navigation Properties
EF Core configures FKs and navigations via:
b.HasOne(...).WithMany(...).HasForeignKey(...).OnDelete(...)
.Navigation(...) for dependent side.
Example: Asset β FieldOffice
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
b.HasOne("IrbyImaging.DomainClasses.FieldOffice", "FieldOffice")
.WithMany("Assets")
.HasForeignKey("FieldOfficeId");
b.Navigation("FieldOffice");
});
- Multiplicity: One
FieldOffice has many Assets.
- Cascade Behavior: Default (no cascade deletion unless specified).
π― Functional Areas & Domain Model
Below is a high-level grouping of the domain entities.
5.1 Asset Management Entities
| Entity |
Purpose |
| Asset |
Base class for all assets (computers, phonesβ¦) |
| Computer, DeskPhone, β¦ |
Inherited types with specific properties |
| AssetModel, AssetModelDetail |
Catalog of asset models |
| Manufacturer, OperatingSystem |
Lookup for manufacturers & OS options |
| FieldOffice, Employee |
Ownership & location information |
5.2 Document Management Entities
| Entity |
Purpose |
| DocumentImage |
Stores scanned image, OCR result & metadata |
| DocumentType, DocumentCategory, DocumentAttribute |
Classification, schema & attributes for docs |
| TempDocumentData, IPMMigration |
Staging of temporary or migrated documents |
| IrbyForms |
Custom form images |
5.3 Job & Field Office Entities
| Entity |
Purpose |
| Job |
Project/job reference |
| FieldOffice |
Local office, linked to employees & assets |
| ODS_Employee, ODS_Jobs_Staging |
Staging tables for external ODSP imports |
5.4 Accounting & Billing Entities
| Entity |
Purpose |
| BillingInvoice |
Invoice record for carrier charges |
| CarrierType, CarrierTypeDetail |
Master/detail for carrier types |
| GeneralLedger, GLTypeDetail |
Chart of accounts & sub-accounts |
5.5 Ticketing System Entities
| Entity |
Purpose |
| Ticket |
Support/IT ticket entry |
| Update |
Timeline updates for tickets |
| Issue |
Generic issue tracker |
5.6 Data Migration & Staging Entities
| Entity |
Purpose |
| TempDocumentData |
Intermediate document storage |
| IPMMigration |
Import of legacy IPM scans |
5.7 Integration & Staging Entities
| Entity |
Purpose |
| ODS_Employee |
Staging for external HR data |
| ODS_Jobs_Staging |
Staging for external job data |
| CovidTestData |
Records of COVID test results & images |
5.8 Miscellaneous Entities
| Entity |
Purpose |
| State |
U.S. states lookup |
| RequestOption |
Dynamic service request options |
π» Sample Code Snippets
6.1 Defining a New Entity
modelBuilder.Entity("IrbyImaging.DomainClasses.MyEntity", b => {
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(200)");
b.HasKey("Id");
b.ToTable("MyEntity", "irby");
});
6.2 Configuring a One-to-Many Relationship
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => {
b.HasOne("IrbyImaging.DomainClasses.Job", "CurrentJob")
.WithMany("Employees")
.HasForeignKey("CurrentJobId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CurrentJob");
});
π UML/ER Diagram (Conceptual)
erDiagram
FIELD_OFFICE ||--o{ ASSET : manages
ASSET_MODEL ||--o{ ASSET : defines
EMPLOYEE ||--o{ ASSET : owns
JOB ||--o{ EMPLOYEE : assigns
DOCUMENT_TYPE ||--o{ DOCUMENT_IMAGE: categorizes
TICKET ||--o{ UPDATE : logs
Note: This high-level ER diagram shows only selected relations.
π Usage & Best Practices
π Conclusion
This auto-generated Designer file:
- Provides a complete snapshot of the EF Core model post-migration.
- Should not be manually editedβany changes are overwritten on scaffolding.
- Serves as a blueprint for EF Core to translate your C# domain model into a SQL Server schema.
By understanding its structure, you can confidently extend your domain, scaffold migrations, and evolve your database schema in a controlled, maintainable way.
Happy Coding! π