🚀 Migration Documentation: 20240301143253_RemoveDocImageFKToWOTable.Designer.cs
File Path:
IrbyImaging.DbContext/Migrations/20240301143253_RemoveDocImageFKToWOTable.Designer.cs
Generated: Auto‑generated EF Core migration snapshot
📋 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Structure
3.1. Auto‑Generated Designer File
3.2. BuildTargetModel Method - Entities Impacted by This Migration
- Model Relationships & Constraint Removal
- Code Walkthrough
- How to Apply the Migration
- Troubleshooting & Tips
- Conclusion
1. Overview & Purpose
✨ Purpose:
This migration snapshot represents the EF Core model after removing the foreign‐key relationship between the DocumentImage and WorkOrder tables.
- Migration Name:
RemoveDocImageFKToWOTable - Intent: Drop the
WorkOrderIdcolumn (and corresponding FK) from theDocumentImageentity, decoupling documents from work orders in the imaging database schema.
Why?
- Decouple storage of scanned documents from workflow orders.
- Simplify the data model for document indexing and retrieval.
- Prepare for a new document–work‑order linking mechanism (e.g., via a linking table or service).
2. Dependencies & Technologies
| Technology | Version / Package |
|---|---|
| .NET | 7.0.x |
| Entity Framework Core | 7.0.7 |
| Database Provider | Microsoft.EntityFrameworkCore.SqlServer |
| Value Conversions | Microsoft.EntityFrameworkCore.Storage |
3. Migration Structure
3.1. Auto‑Generated Designer File
This file is auto‐generated by the dotnet ef migrations add command and contains:
- A partial class for the migration (
RemoveDocImageFKToWOTable). BuildTargetModel(ModelBuilder modelBuilder)— rebuilds the model snapshot after applying the migration.
[DbContext(typeof(IrbyContext))]
[Migration("20240301143253_RemoveDocImageFKToWOTable")]
partial class RemoveDocImageFKToWOTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// ModelBuilder definitions...
}
}
Note:
Do not manually edit this file. Your changes belong in the corresponding*.csmigration file (not.Designer.cs).
3.2. BuildTargetModel Method
-
Annotations:
ProductVersion— EF Core versionRelational:MaxIdentifierLength
-
UseIdentityColumns:
Configures SQL Server identity columns for integer PKs. -
Entity Definitions:
Re‑defines every entity, property, index, table name, discriminator, and relationships as of this migration.
4. Entities Impacted by This Migration
While the model snapshot lists 80+ entities, this migration specifically alters:
DocumentImage
| Property | Type | Notes |
|---|---|---|
DocumentImageId |
Guid |
PK |
— No WorkOrderId |
FK removed | |
FileName, BlobName, ImageContents, … |
various | Document metadata still intact |
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
b.Property<Guid>("DocumentImageId")
.HasColumnType("uniqueidentifier");
// ... other properties ...
b.HasKey("DocumentImageId")
.HasName("PrimaryKey_DocumentImageId");
b.ToTable("DocumentImage", "irby");
});
WorkOrder
| Property | Type | Notes |
|---|---|---|
WorkOrderId |
Guid |
PK |
EquipmentId? |
Guid? |
FK → Equipment (unchanged) |
JobId |
Guid |
FK → Job (unchanged) |
ProjectManagerId? |
Guid? |
FK → Employee |
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.Property<Guid>("WorkOrderId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// ... other properties ...
b.HasKey("WorkOrderId");
b.HasIndex("EquipmentId");
b.HasIndex("JobId");
b.HasIndex("ProjectManagerId");
b.ToTable("WorkOrder", "irby");
});
5. Model Relationships & Constraint Removal
📉 Removed Relationship
Prior to this migration, the DocumentImage entity had:
b.Property<Guid?>("WorkOrderId")
.HasColumnType("uniqueidentifier");
b.HasOne("WorkOrder")
.WithMany("DocumentImages")
.HasForeignKey("WorkOrderId");
After:
- No
WorkOrderIdproperty onDocumentImage.- No navigation from
DocumentImage→WorkOrder.
📈 Unchanged Relationships
WorkOrderretains its FKs toJob,Equipment,Employee.- Other entities remain the same.
UML Relationship Diagram (Before → After)
%%{init: { 'theme': 'base', 'themeVariables': { 'primaryColor':'#fffae6', 'edgeLabelBackground':'#fff' }}}%%
classDiagram
direction LR
class DocumentImage_before {
+Guid DocumentImageId
+Guid? WorkOrderId
}
class WorkOrder {
+Guid WorkOrderId
}
DocumentImage_before --> WorkOrder : fk_WorkOrderId
%% After migration, arrow removed
class DocumentImage_after {
+Guid DocumentImageId
}
DocumentImage_after --x WorkOrder : (removed FK)
6. Code Walkthrough
Key Snippets
// 1. Model-wide annotations
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// 2. DocumentImage entity definition (no WorkOrderId)
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
b.Property<Guid>("DocumentImageId")
.HasColumnType("uniqueidentifier");
// ... other fields ...
b.HasKey("DocumentImageId");
b.ToTable("DocumentImage", "irby");
});
// 3. WorkOrder entity definition (unchanged)
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.Property<Guid>("WorkOrderId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// ... other fields ...
b.HasKey("WorkOrderId");
b.HasIndex("EquipmentId");
b.HasIndex("JobId");
b.HasIndex("ProjectManagerId");
b.ToTable("WorkOrder", "irby");
});
// 4. Relationship config for WorkOrder
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.HasOne("IrbyImaging.DomainClasses.Equipment", "Equipment")
.WithMany()
.HasForeignKey("EquipmentId");
b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
.WithMany()
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
.WithMany()
.HasForeignKey("ProjectManagerId");
});
Change Highlights
| What Changed? | Before | After |
|---|---|---|
DocumentImage.WorkOrderId |
Present as Guid? WorkOrderId property |
Removed |
Navigation on DocumentImage |
HasOne(...).WithMany("...") |
Dropped |
| FK constraint in DB | FOREIGN KEY on DocumentImage table |
Dropped |
7. How to Apply the Migration
- Add the Migration (if not generated):
dotnet ef migrations add RemoveDocImageFKToWOTable - Update the Database:
dotnet ef database update - Verify Changes:
- Inspect the generated SQL (in your output window).
- Confirm
WorkOrderIdcolumn is gone fromirby.DocumentImagetable. - Check no residual FK exists:
EXEC sp_fkeys @pktable_name = 'DocumentImage';
8. Troubleshooting & Tips
- Migration Out‑of‑Sync?
If you manually edited the model without a migration, you may need to:dotnet ef migrations remove dotnet ef migrations add RemoveDocImageFKToWOTable - Cross‑Database References:
Ensure no application code or stored procedure still expectsDocumentImage.WorkOrderId. - Backing Up Data:
If live data exists, back up before dropping FKs/columns.
9. Conclusion
This EF Core designer snapshot confirms the removal of the DocumentImage ↔ WorkOrder foreign‐key relationship. After applying this migration:
- Document storage is decoupled from work orders.
- Your model reflects the new data architecture.
- You can now implement alternate linking strategies (e.g., a linking table or domain service).
🛠️ Next Steps:
- Update your repository interfaces or services that previously traversed
DocumentImage.WorkOrder. - Refactor any UI or API calls expecting that navigation.
Happy Coding! 🎉