📑 IrbyImaging.DbContext Migration Designer
20240301142422_AddDocImageFKToWOTable.Designer.cs
📋 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models & Relationships
- Usage Examples
- Sample Code Snippets
- UML Diagram
- Conclusion
🔍 1. Overview & Purpose
This designer file is auto‑generated by Entity Framework Core and represents a snapshot of the database model after applying the migration named
AddDocImageFKToWOTable
Primary goal:
- Introduce an optional foreign‑key column DocumentImageId into the WorkOrder table.
- Ensure the WorkOrder entity references the DocumentImage entity.
📌 This file is paired with a migration class (AddDocImageFKToWOTable.cs) that contains the Up() and Down() methods.
🛠️ 2. Dependencies & Technologies
| Technology / Package | Version | Role |
|---|---|---|
| Microsoft.EntityFrameworkCore | 7.0.7 | Core ORM, model building, migrations |
| Microsoft.EntityFrameworkCore.Relational | 7.0.7 | Relational database support (SQL Server) |
| Microsoft.EntityFrameworkCore.SqlServer | 7.0.7 | SQL Server provider |
| .NET 7 (.NET 7.0 SDK) | 7.0.x | Runtime & language features |
🔑 3. Key Functional Areas
3.1 Migration Metadata
[DbContext(typeof(IrbyContext))]
[Migration("20240301142422_AddDocImageFKToWOTable")]
partial class AddDocImageFKToWOTable { … }
- DbContext attribute identifies which context this migration belongs to (
IrbyContext). - Migration attribute names the migration and injects a timestamp prefix to guarantee ordering.
3.2 BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// … entity configurations follow …
}
- Purpose: Reconstructs the EF Core model snapshot after the migration.
- Annotations: Capture provider version and conventions (e.g., identity columns).
- Entity Definitions: Describe every table, column, key, index, discriminator, and relationship.
🗄️ 4. Data Models & Relationships
While the snapshot includes dozens of entities, we’ll focus on the core change introduced by this migration.
4.1 WorkOrder Entity
| Column | Type | Nullable | Description |
|---|---|---|---|
| WorkOrderId | uniqueidentifier | No | Primary key |
| Name | nvarchar(max) | Yes | WorkOrder name |
| DocumentImageId | uniqueidentifier | Yes | New FK referencing DocumentImage |
| JobId | uniqueidentifier | No | FK → Job |
| … | … | … | Other properties (dates, status…) |
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.Property<Guid>("WorkOrderId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// New foreign‑key column
b.Property<Guid?>("DocumentImageId")
.HasColumnType("uniqueidentifier");
b.HasKey("WorkOrderId");
// Index on the new FK
b.HasIndex("DocumentImageId");
// Relationship configurations
b.HasOne("IrbyImaging.DomainClasses.DocumentImage", "DocumentImage")
.WithMany()
.HasForeignKey("DocumentImageId");
// …
b.ToTable("WorkOrder", "irby");
});
4.2 DocumentImage Entity
| Column | Type | Nullable | Description |
|---|---|---|---|
| DocumentImageId | uniqueidentifier | No | Primary key |
| FileName | nvarchar(max) | Yes | Original file name |
| ImageContents | varbinary(max) | Yes | Raw image binary |
| DocumentUploadedDate | datetime2 | No | When image was uploaded |
| … | … | … | Various indexing, metadata, role flags |
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
b.Property<Guid>("DocumentImageId")
.HasColumnType("uniqueidentifier");
b.HasKey("DocumentImageId");
b.ToTable("DocumentImage", "irby");
});
4.3 New Foreign‑Key Relationship
WorkOrder (0..1) → DocumentImage (0..*)
classDiagram
class WorkOrder {
+Guid WorkOrderId
+Guid? DocumentImageId
+…
}
class DocumentImage {
+Guid DocumentImageId
+…
}
WorkOrder --> DocumentImage : DocumentImageId
- Multiplicity:
- A WorkOrder can optionally reference a DocumentImage.
- A DocumentImage may be linked to multiple work orders (if reused).
🚀 5. Usage Examples
- Apply the migration
dotnet ef database update 20240301142422_AddDocImageFKToWOTable - Rollback
dotnet ef database update <PreviousMigrationName> - Inspect the snapshot
- Open this designer file (
*.Designer.cs) to see the full model after applying the migration.
- Open this designer file (
🧩 6. Sample Code Snippets
- Verify the new column in LINQ
var workOrdersWithImages = dbContext.WorkOrders .Include(wo => wo.DocumentImage) .Where(wo => wo.DocumentImageId != null) .ToList(); - Add a DocumentImage to a WorkOrder
var image = new DocumentImage { FileName = "report.pdf", DocumentUploadedDate = DateTime.UtcNow }; dbContext.DocumentImages.Add(image); await dbContext.SaveChangesAsync(); var workOrder = await dbContext.WorkOrders.FindAsync(someId); workOrder.DocumentImageId = image.DocumentImageId; await dbContext.SaveChangesAsync();
📈 7. UML Diagram
classDiagram
class WorkOrder {
+Guid WorkOrderId
+string Name
+Guid? DocumentImageId
+DateTime? DateStart
+DateTime? DateComplete
+…
}
class DocumentImage {
+Guid DocumentImageId
+string FileName
+DateTime DocumentUploadedDate
+byte[] ImageContents
+…
}
WorkOrder --> DocumentImage : DocumentImageId
🔚 8. Conclusion
This designer snapshot ensures that EF Core knows the exact state of your model following the AddDocImageFKToWOTable migration.
- It adds an optional FK (
DocumentImageId) to WorkOrder. - It preserves all existing entities, tables, and relationships.
- It serves as a reference for EF Core’s internal change tracking, schema comparison, and future migrations.
Tip: Always commit the designer snapshot alongside your migration code so team members and CI/CD pipelines stay in sync with your database schema.
✨ Happy Coding! ✨