đ AddCostCodeColumnsToClassificationTable.Designer.cs
Auto-generated EF Core migration snapshot for
AddCostCodeColumnsToClassificationTable
This file is part of theIrbyImaging.DbContext.Migrationsnamespace and houses the complete model snapshot after applying the migration.
đ Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models
- UML Diagram
- Helper Methods & Utilities
- Error Handling & Return Types
- API Endpoints Overview
- Thirdâparty Integrations
- Sample Code Blocks
- Usage Examples
- Conclusion
1. Overview & Purpose
This .Designer.cs file is part of an Entity Framework Core migration named AddCostCodeColumnsToClassificationTable. It does not contain the Up() and Down() definitions (those live in the main migration file), but instead defines the postâmigration model snapshot via the BuildTargetModel method. EF Core uses this snapshot to:
- Compare your current model against previous migrations.
- Scaffold future migrations.
- Maintain a source of truth for all tables, columns, keys, indexes, relationships, and types.
đ Key takeaway: Never manually edit designer snapshots. They are auto-generated whenever you run dotnet ef migrations add ... or Update-Database.
2. Dependencies & Technologies
| Dependency | Version/Notes |
|---|---|
| .NET / EF Core | EF Core 9.0.0, SQLÂ Server provider |
| ModelBuilder | Microsoft.EntityFrameworkCore.Metadata |
| Migrations API | Microsoft.EntityFrameworkCore.Migrations |
| Value Conversions | Microsoft.EntityFrameworkCore.Storage.ValueConversion |
3. Key Functional Areas
3.1 Migration Attributes
[DbContext(typeof(IrbyContext))]
[Migration("20250117204950_AddCostCodeColumnsToClassificationTable")]
partial class AddCostCodeColumnsToClassificationTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder) { ... }
}
DbContextattribute: Ties this migration toIrbyContext.Migrationattribute: Uses a timestamped identifier (20250117204950) & the nameAddCostCodeColumnsToClassificationTable.
3.2 BuildTargetModel Method
- Signature:
protected override void BuildTargetModel(ModelBuilder modelBuilder) - Purpose: Recreates the full EF Core model (all tables/entities) at this point in time.
- Behavior:
- Sets global annotations (e.g., product version).
- Configures each entity:
- Properties (name, CLRÂ type, SQL type, nullability).
- Keys (
HasKey). - Indexes (
HasIndex). - Table mapping (
ToTable). - Relationships (
HasOne/WithMany).
3.3 New CostCode Columns
The primary goal of this migration is to add two new columns to the JobClassification table:
| Column Name | CLR Type | SQL Type | Description |
|---|---|---|---|
CostCodeNumber |
int |
int |
Numeric cost code associated with the job. |
CostCodeName |
string |
nvarchar(max) |
Humanâreadable name/description of the code. |
đ Snippet from BuildTargetModel:
modelBuilder.Entity("IrbyImaging.DomainClasses.JobClassification", b =>
{
b.Property<Guid>("JobClassificationId").ValueGeneratedOnAdd().HasColumnType("uniqueidentifier");
// ... existing columns ...
b.Property<int>("CostCodeNumber").HasColumnType("int"); // NEW
b.Property<string>("CostCodeName").HasColumnType("nvarchar(max)"); // NEW
// ... rest of configuration ...
b.ToTable("JobClassification", "irby");
});
These properties will now map to the underlying SQL columns, and EF Core will ensure data is preserved and migrations applied correctly.
3.4 Entity Snapshot Details
This snapshot includes all domain entities â over 120 of them! Below is just a summarized view:
| Entity | Table (Schema) | Key | Sample Properties |
|---|---|---|---|
AccountBalances |
irby.AccountBalances |
AccountBalanceId (GUID) |
AccountingCode, Cost, Revenue, ManHours |
Asset (base) |
irby.Asset |
Id (GUID) |
Category, SerialNumber, PurchaseDate |
JobClassification |
irby.JobClassification |
JobClassificationId (GUID) |
Name, SAMReference, FringeAmount, CostCode* |
Job |
irby.Job |
JobId (GUID) |
Name, JdeNumber, FieldOfficeId, BudgetApproved |
Employee |
irby.Employee |
EmployeeId (GUID) |
FirstName, LastName, JdeNumber, DepartmentId |
| ... | ... | ... | ... |
Note: Each entity is fully configured â indexes, relationships, discriminator columns (for TPH), and SQL types.
4. Data Models
While the full snapshot is enormous, here is how JobClassification now looks conceptually:
public class JobClassification
{
public Guid JobClassificationId { get; set; }
public Guid JobId { get; set; }
public string Name { get; set; }
public int ClassNumber { get; set; }
public decimal FringeAmount { get; set; }
// ⨠New cost code support:
public int CostCodeNumber { get; set; }
public string CostCodeName { get; set; }
public byte[] ImageOCRContents { get; set; }
public string ImageOCRText { get; set; }
// navigation:
public Job Job { get; set; }
}
5. UML Diagram
Below is a PlantUML snippet showing the relationship between Job and JobClassification:
@startuml
entity "Job" as Job {
* JobId : Guid <<PK>>
--
Name : string
JdeNumber : string
// ...
}
entity "JobClassification" as JC {
* JobClassificationId : Guid <<PK>>
--
CostCodeNumber : int
CostCodeName : string
ClassNumber : int
// ...
JobId : Guid <<FK>>
}
Job ||--|{ JC : "Has Classifications"
@enduml
Paste this code in a PlantUMLâenabled tool to render the diagram locally.
6. Helper Methods & Utilities
This designer file is autoâgenerated and contains no custom utility or helper functions. All logic is expressed declaratively via
ModelBuilder.
7. Error Handling & Return Types
- Error Handling: None. EF Core builds the model declaratively; errors surface at designâtime or during migration application.
- Return Types:
voidâ theBuildTargetModelmethod configures the passedModelBuilder.
8. API Endpoints Overview
â Not applicable
This file defines the data model, not any HTTP or web API logic.
9. Thirdâparty Integrations
- Entity Framework Core: Primary ORM for .NET.
- Microsoft SQL Server: Underlying relational database.
- PlantUML (optional): For generating diagrams.
10. Sample Code Blocks
Running the Migration
# Generate a new migration
dotnet ef migrations add AddCostCodeColumnsToClassificationTable
# Apply to the database
dotnet ef database update
Verifying in C#
using (var ctx = new IrbyContext())
{
var classification = new JobClassification
{
JobId = someJobId,
Name = "Electrician",
ClassNumber = 3,
CostCodeNumber = 1001, // new
CostCodeName = "Electrical" // new
};
ctx.JobClassifications.Add(classification);
ctx.SaveChanges();
}
11. Usage Examples
- Query by Cost Code
var codes = ctx.JobClassifications .Where(jc => jc.CostCodeNumber == 1001) .Select(jc => jc.CostCodeName) .Distinct() .ToList(); - Update Existing
var jc = ctx.JobClassifications.Find(existingId); jc.CostCodeName = "Updated Name"; ctx.SaveChanges();
12. Conclusion
⨠AddCostCodeColumnsToClassificationTable.Designer.cs is the EF Core model snapshot after introducing CostCodeNumber and CostCodeName to the JobClassification entity. It:
- Ensures EF Core remembers the entire schema.
- Drives future migrations by comparing old vs. new snapshots.
- Should never be manually edited; treat it as readâonly.
đ With this migration applied, your application can capture and persist cost codes alongside job classifications, unlocking richer reporting and data integrity.