📑 Migration Documentation: AddJobClassAndCostCodeTables.Designer.cs
📂 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- New Data Models
- 4.1 JobClassification
- 4.2 CostCode
- Usage & Examples
- UML Diagram
- Conclusion
📝 Overview & Purpose
This file (AddJobClassAndCostCodeTables.Designer.cs) is an auto-generated part of an Entity Framework Core (EF Core) migration within the IrbyImaging.DbContext project. It defines the target model snapshot for the migration named 20250113132042_AddJobClassAndCostCodeTables.
Why does it exist?
- EF Core uses Designer files to keep track of how the current database model should look after applying this migration.
- It enables
dotnet ef migrationstools to compute differences between migrations and to scaffold appropriate database operations (e.g., creating tables).- Do not edit this file by hand. It is re‑generated whenever you add or remove migrations.
🔗 Dependencies & Technologies
| Technology | Version / Details |
|---|---|
| .NET SDK | ≥ .NET 7.0 |
| Microsoft.EntityFrameworkCore | 9.0.0 (as per [HasAnnotation("ProductVersion","9.0.0")]) |
| SQL Server (Relational) | Uses Identity Columns strategy via UseIdentityColumns() |
- Namespace:
IrbyImaging.DbContext.Migrations - Attributes on the partial class:
[DbContext(typeof(IrbyContext))][Migration("20250113132042_AddJobClassAndCostCodeTables")]
🔑 Key Functional Areas
3.1 BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// 1️⃣ Apply general annotations:
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// 2️⃣ Configure Identity defaults for SQL Server:
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// 3️⃣ Define existing entities (…lots of them…)
// 4️⃣ Define **new** entities:
// • CostCode
// • JobClassification
}
- Purpose: Registers all EF Core entities (tables, columns, keys, relationships) as they should exist after this migration is applied.
- Flow:
- Set model-level annotations
- Enable identity columns for all numeric PKs
- Re‑declare previously existing tables
- Append new tables (
CostCodes,JobClassification)
📊 New Data Models
Below are the two tables introduced by this migration.
4.1 JobClassification
| Column Name | CLR Type | SQL Type | Constraints |
|---|---|---|---|
| JobClassificationId | Guid |
uniqueidentifier |
Primary Key, Auto‑generated |
| ClassNumber | int |
int |
Not nullable |
| FringeAmount | decimal |
decimal(18,2) |
Not nullable |
| ImageOCRContents | byte[] |
varbinary(max) |
Nullable |
| ImageOCRText | string |
nvarchar(max) |
Nullable |
| Name | string |
nvarchar(max) |
Nullable |
| SAMReference | string |
nvarchar(max) |
Nullable |
Mapping Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.JobClassification", b =>
{
b.Property<Guid>("JobClassificationId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<int>("ClassNumber")
.HasColumnType("int");
b.Property<decimal>("FringeAmount")
.HasColumnType("decimal(18,2)");
b.Property<byte[]>("ImageOCRContents")
.HasColumnType("varbinary(max)");
b.Property<string>("ImageOCRText")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<string>("SAMReference")
.HasColumnType("nvarchar(max)");
b.HasKey("JobClassificationId");
b.ToTable("JobClassification", "irby");
});
🔑 Note: This table is created in the
irbyschema.
4.2 CostCode
| Column Name | CLR Type | SQL Type | Constraints |
|---|---|---|---|
| CostCodeId | Guid |
uniqueidentifier |
Primary Key, Auto‑generated |
| CostCodeNumber | int |
int |
Not nullable |
| Name | string |
nvarchar(max) |
Nullable |
Mapping Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.CostCode", b =>
{
b.Property<Guid>("CostCodeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<int>("CostCodeNumber")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("CostCodeId");
b.ToTable("CostCodes");
});
🔑 Note: Uses the default schema (e.g.,
dbo) because no schema is specified.
🛠️ Usage & Examples
- Scaffold the Migration
dotnet ef migrations add AddJobClassAndCostCodeTables - Apply to Database
dotnet ef database update - Inspect
- Verify new tables in SQL Server Management Studio (SSMS)
- Browse
irby.JobClassification - Browse
dbo.CostCodes
📈 UML Diagram (Excerpt)
erDiagram
JobClassification {
Guid JobClassificationId PK
int ClassNumber
decimal FringeAmount
byte[] ImageOCRContents
string ImageOCRText
string Name
string SAMReference
}
CostCode {
Guid CostCodeId PK
int CostCodeNumber
string Name
}
🏁 Conclusion
AddJobClassAndCostCodeTables.Designer.csis a snapshot of the EF Core model after introducing the JobClassification and CostCode tables.- It drives EF Core’s ability to generate database schema changes accurately.
- Remember: Do not manually edit designer files—they are auto‑maintained by EF Core.
✨ Happy Coding with EF Core Migrations! ✨