📑 Migration Designer Documentation
File: IrbyImaging.DbContext/Migrations/20240229193731_AddPurchaseOrderTable.Designer.cs
📖 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models & Relationships
- Usage & Examples
- Conclusion
🧐 Overview & Purpose
This auto‑generated EF Core migration snapshot class represents the target model after applying the
20240229193731_AddPurchaseOrderTable migration against your IrbyContext.
- ✔️ Registers all domain entities (columns, keys, indexes, relationships) via
ModelBuilder. - ➕ Adds the new PurchaseOrder table into the
irbyschema. - 🔄 Acts as a “snapshot” so future migrations can compute differences accurately.
Why “Designer.cs”?
EF Core emits two partial classes for each migration:
- .cs – contains the Up/Down logic
- .Designer.cs – contains the model snapshot (
BuildTargetModel)
🛠 Dependencies & Technologies
| Namespace / Package | Purpose |
|---|---|
Microsoft.EntityFrameworkCore |
Core ORM, model building |
Microsoft.EntityFrameworkCore.Infrastructure |
EF Core internals & services |
Microsoft.EntityFrameworkCore.Metadata |
Model metadata API |
Microsoft.EntityFrameworkCore.Migrations |
Migration support |
Microsoft.EntityFrameworkCore.Storage.ValueConversion |
Column‐type conversions (e.g. DateTimeOffset) |
Microsoft.EntityFrameworkCore.SqlServer |
SQL Server provider (identity, types) |
Tooling: .NET 7.0, EF Core CLI (
dotnet ef migrations add,dotnet ef database update)
Annotations:
ProductVersion= 7.0.7Relational:MaxIdentifierLength= 128
🚀 Key Functional Areas
🔧 BuildTargetModel Method
[DbContext(typeof(IrbyContext))]
[Migration("20240229193731_AddPurchaseOrderTable")]
partial class AddPurchaseOrderTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// Use SQL Server identity columns
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// … registrations of all entities …
}
}
- Annotations describe EF Core version & SQL Server limits.
UseIdentityColumnsconfigures auto‑incrementing PKs for SQL Server.
🗂 Entity Mappings
This snapshot includes every domain entity, but here we focus on the newly added PurchaseOrder.
▶️ PurchaseOrder Entity
| Column | CLR Type | SQL Type | Constraint |
|---|---|---|---|
| PurchaseOrderId | Guid |
uniqueidentifier |
PK, ValueGeneratedOnAdd |
| Description | string |
nvarchar(max) |
|
| DisplayName | string |
nvarchar(max) |
|
| JobId | Guid |
uniqueidentifier |
FK → Job, Required |
| Name | string |
nvarchar(max) |
|
| OrderDate | DateTime? |
datetime2 |
Nullable |
| OrderNumber | string |
nvarchar(max) |
|
| Org_Bu | string |
nvarchar(max) |
|
| Org_IntDivision | string |
nvarchar(max) |
|
| Type | string |
nvarchar(max) |
|
| VendorName | string |
nvarchar(max) |
|
| VendorNumber | string |
nvarchar(max) |
modelBuilder.Entity("IrbyImaging.DomainClasses.PurchaseOrder", b =>
{
b.Property<Guid>("PurchaseOrderId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<string>("DisplayName")
.HasColumnType("nvarchar(max)");
b.Property<Guid>("JobId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("OrderDate")
.HasColumnType("datetime2");
b.Property<string>("OrderNumber")
.HasColumnType("nvarchar(max)");
b.Property<string>("Org_Bu")
.HasColumnType("nvarchar(max)");
b.Property<string>("Org_IntDivision")
.HasColumnType("nvarchar(max)");
b.Property<string>("Type")
.HasColumnType("nvarchar(max)");
b.Property<string>("VendorName")
.HasColumnType("nvarchar(max)");
b.Property<string>("VendorNumber")
.HasColumnType("nvarchar(max)");
b.HasKey("PurchaseOrderId");
b.HasIndex("JobId");
b.ToTable("PurchaseOrder", "irby");
});
- Primary Key:
PurchaseOrderId(GUID). - Index on
JobIdfor fast join operations. - FK Constraint: each PurchaseOrder ⟶ one Job (
JobId).
🔗 Data Models & Relationships
🖼 PurchaseOrder Class Diagram
classDiagram
class PurchaseOrder {
+Guid PurchaseOrderId
+string Description
+string DisplayName
+Guid JobId
+string Name
+DateTime? OrderDate
+string OrderNumber
+string Org_Bu
+string Org_IntDivision
+string Type
+string VendorName
+string VendorNumber
}
class Job {
+Guid JobId
+string Name
+string JobNumber
// …other properties…
}
PurchaseOrder --> Job : JobId
- Association: 1 PurchaseOrder → 1 Job
📚 Usage & Examples
-
Apply the Migration
dotnet ef database update 20240229193731_AddPurchaseOrderTable -
Verify in Database
- Connect with SSMS/Azure Data Studio
- Expand
irby.PurchaseOrdertable
-
C# Domain Example
var po = new PurchaseOrder { JobId = someJobId, OrderNumber = "PO-2024-123", VendorName = "Acme Supplies", OrderDate = DateTime.UtcNow, DisplayName = "Acme Supplies January 2024" }; context.PurchaseOrders.Add(po); context.SaveChanges();
🏁 Conclusion
This Designer.cs file is your EF Core model snapshot after the AddPurchaseOrderTable migration. It:
- Registers the complete domain model (entities, fields, FKs)
- Introduces the new PurchaseOrder table in the irby schema
- Ensures future migrations can calculate deltas accurately
Keep it under source control ✨, and use dotnet ef commands to manage schema changes seamlessly!