π RemoveZipCodeColumn.Designer.cs Documentation
File Path:
IrbyImaging.DbContext/Migrations/20250116130013_RemoveZipCodeColumn.Designer.cs
π Table of Contents
- Overview & Purpose
- Migration Metadata & Annotations
- BuildTargetModel: The Model Snapshot
- Key Entity Configurations
- Relationships & Foreign Keys
- Indexes & Constraints
- UML Diagrams
- How to Use This Designer File
- Sample Commands & Usage
- Conclusion
1. Overview & Purpose
π What is this file?
This is an auto-generated EF Core designer file for the RemoveZipCodeColumn migration in the IrbyImaging.DbContext. It contains the BuildTargetModel method, which represents a complete snapshot of the Entity Framework Core model after applying the migration.
π Why does it exist?
- Migrations: EF Core tracks schema changes over time. Each migration has two parts:
- The main migration file (
Up/Downmethods). - A .Designer.cs file capturing the full model state at that point.
- The main migration file (
- The designer file ensures EF Core knows how to construct SQL to reach that state and supports scaffolding, diffing, and model snapshotting.
2. Migration Metadata & Annotations
At the top of BuildTargetModel, youβll see two annotations:
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
- ProductVersion: EF Core version used to generate the model.
- MaxIdentifierLength: Maximum length for table/column names in the target RDBMS (here, SQL Server = 128).
- UseIdentityColumns: Configures SQL Server to use
IDENTITYfor auto-increment keys.
3. BuildTargetModel: The Model Snapshot
The core method:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// βββ Global annotations ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// βββ Entity configurations βββββββββββββββββββββββββββββββββββββββββββββββββ
modelBuilder.Entity("IrbyImaging.DomainClasses.Job", b => { β¦ });
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => { β¦ });
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { β¦ });
// β¦ dozens of other domain classes β¦
}
Note: You should never manually edit this file. Changes here will be overwritten by subsequent migrations.
4. Key Entity Configurations
Below are a few representative entities showing how columns, keys, and table/schema names are mapped.
4.1 Job
modelBuilder.Entity("IrbyImaging.DomainClasses.Job", b =>
{
b.Property<Guid>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("JdeNumber")
.HasColumnType("nvarchar(450)");
// β¦ other properties β¦
b.Property<string>("ZipCode")
.HasColumnType("nvarchar(max)");
b.HasKey("JobId");
b.HasIndex("JdeNumber")
.IsUnique()
.HasFilter("[JdeNumber] IS NOT NULL");
b.ToTable("Job", "irby");
});
4.2 LeaseDetails
This entity captures leaseβspecific details extracted from documents.
4.3 Asset Hierarchy
EF Coreβs TableβperβHierarchy (TPH) inheritance is used for Asset:
classDiagram
Asset <|-- Computer
Asset <|-- DeskPhone
Asset <|-- MobileDevice
Asset <|-- OfficePrinter
Asset : +Guid Id
Asset : +string Category
Asset : +string SerialNumber
Computer : +string AssetNumber
MobileDevice : +string Imei
// β¦ more derived types β¦
- Discriminator column: identifies subtype
- All assets are stored in
irby.Assettable
4.4 Employee & Department
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
b.Property<Guid>("EmployeeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("JdeNumber")
.HasColumnType("nvarchar(450)");
// β¦ address, status, zip β¦
b.HasIndex("JdeNumber")
.IsUnique()
.HasFilter("[JdeNumber] IS NOT NULL");
b.HasOne("IrbyImaging.DomainClasses.Department", "Department")
.WithMany()
.HasForeignKey("DepartmentId");
b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
.WithMany("Employees")
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Cascade);
b.ToTable("Employee", "irby");
});
- Employee β references Job (cascade on delete)
- Employee β optional Department
5. Relationships & Foreign Keys
A few common patterns:
| Principal Entity | Dependent Entity | Navigation | FK Property | Cascade Behavior |
|---|---|---|---|---|
| FieldOffice | Job | Jobs |
FieldOfficeId |
none |
| Job | Employee | Employees |
JobId |
Cascade on delete |
| Employee | LinkUserRole | User |
EmployeeId |
Cascade on delete |
| Role | LinkRolePermission | Role |
RoleId |
Cascade on delete |
| GeneralLedger | GLTypeDetail | GLTypeDetail |
GeneralLedgerId |
none |
6. Indexes & Constraints
-
Unique Indexes:
Job.JdeNumberEmployee.JdeNumberFieldOffice.JdeNumberMobileDevice.Imei
-
Composite PKs: None in this snapshot (all use singleβcolumn keys).
-
Default Schemas:
- Most tables live in
irbyschema. - A few (ODS*) live in default schema without
irby.
- Most tables live in
7. UML Diagrams
7.1 Basic JobβFieldOfficeβEmployee Relationship
classDiagram
FieldOffice "1" o-- "*" Job : hosts
Job "1" *-- "*" Employee : employs
7.2 Asset Inheritance
classDiagram
Asset <|-- Computer
Asset <|-- DeskPhone
Asset <|-- MobileDevice
Asset : +Guid Id
Asset : +string Category
Asset : +string Status
Computer : +string AssetNumber
DeskPhone : +string MacAddress
MobileDevice : +string Imei
8. How to Use This Designer File
- EF Core Infrastructure will autoβload this snapshot when you run:
dotnet ef database update 20250116130013_RemoveZipCodeColumn - Do NOT modify manuallyβany edits here will be lost.
- To adjust the schema, modify your domain classes, then run:
dotnet ef migrations add YourNewChange
9. Sample Commands & Usage
# 1. Add a new migration (e.g., removing ZipCode)
dotnet ef migrations add RemoveZipCodeColumn
# 2. Apply migrations to update the database
dotnet ef database update
# 3. Roll back to a previous migration
dotnet ef database update LastGoodMigrationName
π§ Internally, EF Core will use this .Designer.cs file to compute the diff between the current model snapshot and the one stored in the database.
10. Conclusion
This RemoveZipCodeColumn.Designer.cs file is a critical part of EF Coreβs migration machinery:
- π― It captures a readβonly snapshot of your entire model.
- π§ Itβs used to generate SQL during
Up/Downoperations. - π Leave it untouched; treat it as a black box.
By following the patterns above, youβll maintain a clear, consistent database evolution path as your domain model changes over time. Happy coding! πβ¨