🚀 Migration Documentation:
20240201184940_UpdateEmployeeTableWithNewColumns3.Designer.cs
📋 Table of Contents
- Overview & Purpose
- File Structure & Context
- BuildTargetModel Method
- Key Entity: Employee 🧑💼
- Other Major Entities
- Inheritance & Discriminators 🌳
- Relationships & Navigation Properties 🔗
- Dependencies & Technologies
- Usage & Execution
- Conclusion
1. Overview & Purpose
This file is an auto-generated part of an Entity Framework Core Migration:
- Name:
UpdateEmployeeTableWithNewColumns3.Designer.cs - Context: Appears under
IrbyImaging.DbContext/Migrations - Role: Defines the target model for EF Core after applying the migration.
- Why It Matters:
- Keeps a snapshot of the entire EF Core model at this point in time.
- Ensures that when you run
dotnet ef migrations add/update, EF knows what the database schema should look like. - DO NOT manually edit this file—changes are handled via the corresponding
.csmigration file.
2. File Structure & Context
IrbyImaging.DbContext/
└── Migrations/
├── 20240201184940_UpdateEmployeeTableWithNewColumns3.cs
├── 20240201184940_UpdateEmployeeTableWithNewColumns3.Designer.cs ← (this file)
└── __EFMigrationsHistory
.Designer.cs: Contains theBuildTargetModel(ModelBuilder modelBuilder)override, declaring all entities, properties, keys, indexes, relationships, and inheritance mappings for the snapshot.
3. BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// EF Core annotations
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// Enable SQL Server identity columns
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// *** Entity Definitions Follow ***
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => { /* ... */ });
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { /* ... */ });
// ... many more entities ...
}
- Annotations at the top describe provider-specific settings.
- Entities registration: One big fluent API call per entity.
4. Key Entity: Employee 🧑💼
4.1 New Columns Introduced
This migration’s name implies new columns for the Employee table. Below is the complete set of properties EF maps, with bold for the likely new additions:
| Column Name | CLR Type | SQL Type | Nullable? | Notes |
|---|---|---|---|---|
| EmployeeId | Guid |
uniqueidentifier |
No | Primary Key (ValueGeneratedOnAdd) |
| AzureUserId | Guid |
uniqueidentifier |
No | New - link to Azure AD user |
| Birthday | DateTime? |
datetime2 |
Yes | |
| BusinessUnit | string |
nvarchar(max) |
Yes | New |
| City | string |
nvarchar(max) |
Yes | |
| County | string |
nvarchar(max) |
Yes | |
| DepartmentId | Guid? |
uniqueidentifier |
Yes | FK to Department |
| DisplayName | string |
nvarchar(max) |
Yes | New |
string |
nvarchar(max) |
Yes | ||
| EmploymentStartDate | DateTime? |
datetime2 |
Yes | |
| FLSAExemption | string |
nvarchar(max) |
Yes | New |
| FirstName | string |
nvarchar(max) |
Yes | |
| JdeNumber | string |
nvarchar(450) |
Yes | Unique Index |
| JobId | Guid |
uniqueidentifier |
No | FK to Job |
| LastFourSSN | string |
nvarchar(max) |
Yes | |
| LastJob | string |
nvarchar(max) |
Yes | |
| LastJobDate | DateTime? |
datetime2 |
Yes | |
| LastName | string |
nvarchar(max) |
Yes | |
| ManagerId | Guid? |
uniqueidentifier |
Yes | FK to Employee (self‑reference) |
| ManagerName | string |
nvarchar(max) |
Yes | |
| MiddleName | string |
nvarchar(max) |
Yes | |
| OfficePhone | string |
nvarchar(max) |
Yes | |
| PayType | string |
nvarchar(max) |
Yes | |
| RehireDate | DateTime? |
datetime2 |
Yes | |
| RoleId | Guid? |
uniqueidentifier |
Yes | FK to Role |
| State | string |
nvarchar(max) |
Yes | |
| Status | string |
nvarchar(max) |
No | Required |
| StreetAddress | string |
nvarchar(max) |
Yes | |
| TerminatedDate | DateTime? |
datetime2 |
Yes | |
| Title | string |
nvarchar(max) |
Yes | |
| UARApprover | bool |
bit |
No | |
| UserName | string |
nvarchar(max) |
Yes | |
| WorkEmail | string |
nvarchar(max) |
Yes | |
| Zip | string |
nvarchar(max) |
Yes |
Tip: The bold columns are likely the new additions in this migration.
4.2 Indexes & Constraints
PK_Employeeon EmployeeId- Unique Index on
JdeNumber(filtered: NON NULL) - FKs:
DepartmentId→Department(DepartmentId)JobId→Job(JobId)(Required)RoleId→Role(RoleId)
5. Other Major Entities
This snapshot covers 40+ domain classes. A summary of a few important ones:
| Entity | Table (Schema) | Purpose |
|---|---|---|
| Asset | irby.Asset |
Base for TPH (Computer, MobileDevice…) |
| AssetHistory | irby.AssetHistory |
Track asset changes & audit trail |
| AssetModel | irby.AssetModel |
Metadata for asset types (e.g., models of laptops) |
| AuditDetail | irby.AuditDetail |
User action logging |
| BillingInvoice | irby.BillingInvoice |
Billing / invoicing records |
| Department | irby.Department |
Company department reference |
| Job | irby.Job |
Customer project/job details |
| Role, Permissions | irby.Role, irby.Permissions |
RBAC implementation |
TimeSheetEntry, TimeEntryType |
irby.TimeSheetEntry |
Employee time‑tracking |
| DocumentImage, TempDocumentData | irby.DocumentImage |
Document management |
| …and many more |
6. Inheritance & Discriminators 🌳
The Asset entity uses Table-per-Hierarchy (TPH):
- Base:
IrbyImaging.DomainClasses.Asset - Derived:
Computer,DeskPhone,Dock,MobileDevice,Monitor,NetworkEquipment,OfficePrinter,Printer,SafetyEquipment - Discriminator Column:
Discriminator(string)
classDiagram
Asset <|-- Computer
Asset <|-- MobileDevice
Asset <|-- DeskPhone
Asset <|-- SafetyEquipment
Asset : +Guid Id
Asset : +string SerialNumber
Computer : +string AssetNumber
MobileDevice : +string Imei
7. Relationships & Navigation Properties 🔗
At the bottom of the snapshot, EF wires up FKs with navigation:
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => {
b.HasOne("IrbyImaging.DomainClasses.Department", "Department")
.WithMany()
.HasForeignKey("DepartmentId");
// ...
b.Navigation("Department");
});
- One‑to‑Many:
- Employee → Assets
- Job → Employees
- FieldOffice → Assets / Jobs
- Self‑Reference:
- Employee.Manager ↔ Employee
- Link Tables:
LinkUserRole: Employee ↔ RoleLinkRolePermission: Role ↔ Permissions
8. Dependencies & Technologies
- .NET 7 / C# 11
- Entity Framework Core v7.0.7
- SQL Server Provider (UseIdentityColumns)
- Domain Classes living in
IrbyImaging.DomainClasses
9. Usage & Execution
- Adding a Migration
dotnet ef migrations add UpdateEmployeeTableWithNewColumns3 - Review
.csfile for Up/Down logic (this file is only the model snapshot). - Apply Migration
dotnet ef database update - Verify: The
Employeetable in your database will now include the newly introduced columns, constraints, and indexes.
10. Conclusion 🎯
- This Designer snapshot captures the entire EF Core model after the migration.
- It is critical for EF’s internal change detection but should remain unmodified by developers.
- Always work with the corresponding
.csmigration for schema changes and let EF regenerate this snapshot.
Happy Coding! 🚀