📚 Documentation: AddWIPTable.Designer.cs
Project: IrbyImaging.DbContext
Namespace:IrbyImaging.DbContext.Migrations
File:20240522182056_AddWIPTable.Designer.cs
Migration:AddWIPTable
🗂 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Summary
- Key Entities Affected
- New Table: WIP
- BuildTargetModel Walkthrough
- UML Class Diagram
- Code Snippets & Examples
- Usage & Applying the Migration
- Conclusion
🔍 Overview & Purpose
The AddWIPTable.Designer.cs is an auto‑generated designer file for the Entity Framework Core migration named AddWIPTable. Its primary role is to describe the target model snapshot after applying this migration.
- Why Designer?
- Tracks the internal shape of your EF Core model at this point in time.
- Used by EF Core tools to compute subsequent migrations.
- Core Functionality
- Implements
BuildTargetModel(ModelBuilder)to configure every entity, property, index, discriminator, and relationship in the context. - Registers the new WIP table along with hundreds of existing domain tables.
- Implements
🛠 Dependencies & Technologies
| Dependency | Version / Notes |
|---|---|
| .NET / C# | 7.0.7 (ProductVersion) |
| Entity Framework Core | EF Core 7.0.x |
| Database Provider | Microsoft SQL Server (Relational: MaxIdentifierLength=128) |
| Value Converters | None specific in this migration |
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.7">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
📝 Migration Summary
- Migration Name:
20240522182056_AddWIPTable - Context:
IrbyContext - Change:
- Added a new entity/table WIP under schema irby.
- Reflected within the
BuildTargetModelso that EF tooling knows how to map WIP.
🎯 Key Entities Affected
While this migration focuses on the WIP entity, the designer file re‑enumerates EVERY existing domain class in the model at this snapshot. For brevity, here are a few highlights:
| Entity | Schema | Notes |
|---|---|---|
| Asset | irby | TPH base class with discriminators |
| Employee | irby | FK → Department, Job, Role |
| Job | irby | Index on JdeNumber |
| DocumentImage | irby | Multi‑purpose imaging metadata |
| … | … | … |
| WIP | irby | NEW |
🚀 All other entities are preserved verbatim to maintain model consistency.
🆕 New Table: WIP
| Column Name | CLR Type | SQL Type | Notes |
|---|---|---|---|
| WIPId | Guid |
uniqueidentifier | Primary Key, ValueGeneratedOnAdd |
| BIEC | decimal |
decimal(18,2) | |
| CIEB | decimal |
decimal(18,2) | |
| ChildJob | bool |
bit | |
| Cost | decimal |
decimal(18,2) | |
| CostYTD | decimal |
decimal(18,2) | |
| Customer | string |
nvarchar(max) | |
| Division | string |
nvarchar(max) | |
| FieldOffice | string |
nvarchar(max) | |
| JobName | string |
nvarchar(max) | |
| JobNumber | string |
nvarchar(max) | |
| Lead | string |
nvarchar(max) | |
| ManHours | decimal |
decimal(18,2) | |
| Margin | decimal |
decimal(18,2) | |
| MarginPct | decimal |
decimal(18,2) | |
| MarginYTD | decimal |
decimal(18,2) | |
| MarginYTDPct | decimal |
decimal(18,2) | |
| ParentJob | bool |
bit | |
| ParentJobNumber | string |
nvarchar(max) | |
| ReportMonth | int |
int | |
| ReportYear | int |
int | |
| Revenue | decimal |
decimal(18,2) | |
| RevenueYTD | decimal |
decimal(18,2) | |
| State | string |
nvarchar(max) | |
| TypeOfWork | string |
nvarchar(max) | |
| Unbilled | decimal |
decimal(18,2) | |
| updatedBy | string |
nvarchar(max) | |
| updatedDate | DateTime |
datetime2 |
📦 Key Configuration
modelBuilder.Entity("IrbyImaging.DomainClasses.WIP", b => { b.HasKey("WIPId"); b.ToTable("WIP", "irby"); // … all property mappings above … });
🔨 BuildTargetModel Walkthrough
-
Annotations & Identity Columns
- Sets product version and max identifier length.
- Applies
UseIdentityColumns()globally for SQL Server.
-
Entity Definitions
- For each CLR type in the domain, the
.Entity(string, action)block:- Declares properties (
.Property<…>("Name")). - Configures column types, nullability, identity, default values.
- Defines keys (
.HasKey(...)), indices (.HasIndex(...)), table and schema names. - Configures TPH (Table‑Per‑Hierarchy) discriminators for inheritance.
- Declares properties (
- For each CLR type in the domain, the
-
Relationships
- After declaring all entities, EF establishes FKs and navigation properties:
modelBuilder.Entity("Asset") .HasOne("IrbyImaging.DomainClasses.FieldOffice", "FieldOffice") .WithMany("Assets") .HasForeignKey("FieldOfficeId"); - This ensures referential integrity in the generated SQL.
- After declaring all entities, EF establishes FKs and navigation properties:
-
Snapshot Integrity
- Because this is a designer snapshot, it repeats the full model so future migrations can diff accurately.
🖼 UML Class Diagram
classDiagram
class WIP {
+Guid WIPId
+decimal BIEC
+decimal CIEB
+bool ChildJob
+decimal Cost
+decimal CostYTD
+string Customer
+string Division
+string FieldOffice
+string JobName
+string JobNumber
+string Lead
+decimal ManHours
+decimal Margin
+decimal MarginPct
+decimal MarginYTD
+decimal MarginYTDPct
+bool ParentJob
+string ParentJobNumber
+int ReportMonth
+int ReportYear
+decimal Revenue
+decimal RevenueYTD
+string State
+string TypeOfWork
+decimal Unbilled
+string updatedBy
+DateTime updatedDate
}
📋 Code Snippets & Examples
1. Declaring the WIP Entity
modelBuilder.Entity("IrbyImaging.DomainClasses.WIP", b =>
{
b.Property<Guid>("WIPId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<decimal>("Cost")
.HasColumnType("decimal(18,2)");
// … other properties …
b.HasKey("WIPId");
b.ToTable("WIP", "irby");
});
2. Adding a Migration (CLI)
# After editing your DbContext or adding the WIP entity class
dotnet ef migrations add AddWIPTable
dotnet ef database update
3. Using the WIP DbSet
public class IrbyContext : DbContext
{
public DbSet<WIP> WIPEntries { get; set; }
// … other DbSets …
}
// Query example
var januaryReport = context.WIPEntries
.Where(w => w.ReportMonth == 1 && w.ReportYear == 2024)
.ToList();
🚀 Usage & Applying the Migration
- Ensure your
WIPdomain class exists in theIrbyImaging.DomainClassesproject. - Run the EF Core tools:
dotnet ef migrations add AddWIPTable dotnet ef database update - Verify the new WIP table appears under schema
irbyin your SQL Server instance. - Query and manipulate via the generated
DbSet<WIP>on yourIrbyContext.
🏁 Conclusion
The AddWIPTable.Designer.cs file is a critical snapshot in the EF Core migrations pipeline. It ensures that:
- Your WIP entity is correctly mapped to the database.
- All existing tables and relationships are preserved.
- Future migrations can diff against this precise shape of the model.
🎉 With this migration in place, you can now track Work‑In‑Progress (WIP) metrics directly in your database, empowering reporting and analytics in the Irby Imaging platform.
📌 For any further customization (indexes, constraints, relationships), modify the Up() / Down() methods in the sibling migration file 20240522182056_AddWIPTable.cs and re‑scaffold as needed.