π Migration Documentation: 20240307125652_ChangeJobIdToNullable.Designer.cs
File Path:
IrbyImaging.DbContext/Migrations/20240307125652_ChangeJobIdToNullable.Designer.cs
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- BuildTargetModel Method Walkthrough
- Entities & Mappings
- Relationships & Navigation Properties
- Migration Change:
JobIdβ Nullable - How to Use This Migration
- Sample Code & CLI Commands
- Simplified UML Diagram
- Conclusion
π 1. Overview & Purpose
The Designer file is an auto-generated snapshot of your Entity Framework Core model after applying the migration named ChangeJobIdToNullable. It contains:
- A
BuildTargetModel(ModelBuilder modelBuilder)method. - Fluent API calls to configure entities, properties, keys, indexes, discriminators, relationships, and table schemas.
- The EF Core metadata representing the target state of your database schema.
Why this file exists
EF Core migrations split into two classes:
- Migration class (
20240307125652_ChangeJobIdToNullable.cs) β holdsUp()/Down()to apply/revert changes.- Designer class (
β¦Designer.cs) β holds theBuildTargetModel()snapshot of the entire model.
π οΈ 2. Dependencies & Technologies
| Technology | Version |
|---|---|
| .NET SDK | 7.0.x |
| Entity Framework Core | 7.0.7 |
| Database Provider | Microsoft SQL Server |
| Migrations | Code-based, Fluent API |
Key NuGet Packages:
Microsoft.EntityFrameworkCoreMicrosoft.EntityFrameworkCore.SqlServerMicrosoft.EntityFrameworkCore.Design
β¨ 3. Key Functional Areas
-
Model Snapshot
Captures the state of all EF entities and relations post-migration. -
Property Configurations
- Column types (e.g.,
nvarchar(max),uniqueidentifier). - Identity/auto-generated keys.
- Nullable vs. required properties.
- Column types (e.g.,
-
Table & Schema Mapping
- Custom schemas (e.g.,
"irby"). - Table-per-hierarchy discriminators for polymorphic assets.
- Custom schemas (e.g.,
-
Indexes & Constraints
- Unique filters (e.g.,
JdeNumber IS NOT NULL). - Foreign-key indexes.
- Unique filters (e.g.,
-
Discriminator Configuration
- Single-table inheritance for
Assetsubtypes:Computer,MobileDevice, etc.
- Single-table inheritance for
π¨ 4. BuildTargetModel Method Walkthrough
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// Use SQL Server identity/sequence columns
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// Entity-by-entity configuration begins...
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { β¦ });
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => { β¦ });
// (dozens more)
// Relationship configuration at the end:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
b.HasOne("IrbyImaging.DomainClasses.FieldOffice", "FieldOffice")
.WithMany("Assets")
.HasForeignKey("FieldOfficeId");
// ...
});
}
HasAnnotation: Tracks EF Core version & provider specifics.UseIdentityColumns: Configures PKs to auto-increment via IDENTITY in SQL Server.Entity(...)block: Defines properties, keys, indexes, discriminator values, table names, schema.
π 5. Entities & Mappings
Below is a highβlevel summary of the dozens of domain entities defined in this migration. Each entity block maps to a table or view in your database.
Asset Management
| Entity | Table (Schema) | Notes |
|---|---|---|
| Asset | Asset (irby) |
TPH root, discriminator column |
| β’ Computer | same | Discriminator: "Computer" |
| β’ MobileDevice | same | Unique IMEI index, custom column mapping |
| β’ DeskPhone / Printer | same | Subtypes of Asset |
| AssetModel | AssetModel (irby) |
FK β Manufacturer |
| AssetModelDetail | AssetModelDetail |
Detailed options |
| Manufacturer | AssetManufacturer (irby) |
|
| AssetHistory | AssetHistory (irby) |
Tracks audit trail |
Document Management
| Entity | Table (Schema) | Notes |
|---|---|---|
| DocumentImage | DocumentImage (irby) |
BLOB + OCR + indexing |
| DocumentAttribute | DocumentAttribute (irby) |
Index field definitions |
| DocumentCategory | DocumentCategory (irby) |
|
| DocumentType | DocumentType (irby) |
|
| BlobData | BlobData (irby) |
Temporary binary storage |
| TempDocumentData | TempDocumentData (irby) |
Staging area |
| IrbyForms | IrbyForms (irby) |
Legacy form storage |
| IPMMigration | IPMMigration (irby) |
Import migration staging |
People & HR
| Entity | Table (Schema) | Notes |
|---|---|---|
| Employee | Employee (irby) |
FK β Job, Department, Role |
| Department | Department (irby) |
Organizational unit |
| Role | Role (irby) |
Security roles |
| Permissions | Permissions (irby) |
|
| LinkUserRole | LinkUserRole (irby) |
Junction table |
| LinkRolePermission | LinkRolePermission (irby) |
|
| TimeEntryType | TimeEntryType (irby) |
Timesheet categories |
| TimeSheetEntry | TimeSheetEntry (irby) |
Hours logged |
Field Offices & Jobs
| Entity | Table (Schema) | Notes |
|---|---|---|
| FieldOffice | FieldOffice (irby) |
FK β multiple Employee roles |
| Job | Job (irby) |
FK β FieldOffice, unique JDE idx |
| JobAndFieldOfficeMapping | JobAndFieldOfficeMapping |
Reporting view |
| WorkOrder | WorkOrder (irby) |
FK β Job |
Reporting & Finance
| Entity | Table / View | Notes |
|---|---|---|
| BillingInvoice | BillingInvoice (irby) |
Invoicing data |
| CarrierType / Detail | CarrierType (irby), CarrierTypeDetail |
|
| GeneralLedger / GLTypeDetail | GeneralLedger (irby), GLTypeDetail |
|
| PurchaseOrder | PurchaseOrder (irby) |
FK β Job |
| ContractTypeDetails, ContractTypeNumber, ContractsByLead | Views / tables for contract reporting | |
| LeaseDetails, LeasePropertyDetails, DirectorLeaseInfo, DirectorProperties | Real estate cost analytics | |
| LicenseReport, GeoLocations, StatePropertyCosts | Various reporting tables |
Third-Party / ODS Imports
| Entity | Table | Notes |
|---|---|---|
| ODSEmployee, ODSCustomer, ODSJob | ODSEmployees, ODSCustomers, ODSJobs |
Imported from external system |
| OperatingSystem | OperatingSystem (irby) |
Lookups for device OS |
| Vehicle | Vehicle (irby) |
Light-weight reference |
| Ticket / Update | Ticket (irby), Update (irby) |
Support ticketing |
| COVID Test Data | CovidTestData (irby) |
Health screening records |
| LytxTemplate | LytxTemplate (irby) |
Telematics import snapshot |
π 6. Relationships & Navigation Properties
-
1:N
FieldOfficeβ manyAssets,JobsJobβ manyEmployees,WorkOrdersEmployeeβ manyAssets, manyTimeSheetEntryTicketβ manyUpdates
-
N:1
Assetβ oneModel, oneFieldOffice, oneOwner (Employee)
-
Many-to-Many (via junction tables)
User β RolethroughLinkUserRoleRole β PermissionthroughLinkRolePermission
Discriminator-based inheritance generates a single Asset table for subtypes.
π οΈ 7. Migration Change: JobId β Nullable
The core change introduced by ChangeJobIdToNullable is to allow the JobId foreign key in certain entities (e.g., Employee, Equipment) to be nullable.
- Before:
b.Property<Guid>("JobId") .IsRequired() // non-nullable .HasColumnType("uniqueidentifier"); - After:
b.Property<Guid?>("JobId") .HasColumnType("uniqueidentifier"); - Effect: Employees (or other entities) can now exist without an associated Job.
While the Designer snapshot shows the resulting model, the Up() method in the companion file will issue:
migrationBuilder.AlterColumn<Guid?>(
name: "JobId",
table: "Employee",
type: "uniqueidentifier",
nullable: true,
oldClrType: typeof(Guid),
oldType: "uniqueidentifier");
π 8. How to Use This Migration
-
Add Migration
(Already done)dotnet ef migrations add ChangeJobIdToNullable -
Update Database
Applies all pending migrations to your SQL Server database:dotnet ef database update -
Inspect Schema
Verify thatEmployee.JobId(and any other adjusted columns) now allowsNULL. -
Roll Back (if needed)
dotnet ef database update LastGoodMigrationName
π» 9. Sample Code & CLI Commands
# 1. Install EF Tools (if not already)
dotnet tool install --global dotnet-ef
# 2. Scaffold new migration
dotnet ef migrations add ChangeJobIdToNullable -c IrbyContext
# 3. Apply to DB
dotnet ef database update
Example usage in code:
using (var context = new IrbyContext())
{
// Now you can create an Employee without a Job:
var unassigned = new Employee
{
FirstName = "Jane",
LastName = "Doe",
JobId = null, // Was not possible before!
Status = "Active"
};
context.Employees.Add(unassigned);
context.SaveChanges();
}
π 10. Simplified UML Diagram
classDiagram
FieldOffice "1" --> "*" Asset : Houses
FieldOffice "1" --> "*" Job : Manages
Asset <|-- Computer
Asset <|-- MobileDevice
Employee "0..*" --> "1" Job : WorksOn
Employee "0..*" --> "*" Asset : Owns
Job "1" --> "*" Employee : Employs
Job "1" --> "*" WorkOrder : Contains
Role "1" --> "*" LinkUserRole : Grants
Permission "1" --> "*" LinkRolePermission : Authorizes
Note: This Mermaid diagram is a simplified subset focusing on core classes.
β 11. Conclusion
This Designer snapshot is crucial for EF Coreβs migration engine to understand the end state of your model. It:
- Captures every entity, property, index, and relationship.
- Ensures your
ChangeJobIdToNullablemigration can be applied deterministically across environments. - Enables you to evolve your domain model safely via code-first migrations.
By reviewing this documentation, you now have:
- A clear structure of your database schema.
- Insight into the nullable JobId change.
- Guidance on running and reverting this migration.
Happy coding! π