📄 Documentation: AddCostCodeType.Designer.cs
📗 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models & View Models
- BuildTargetModel Method
- Entity Spotlight: CostCode
- Relationships & Conventions
- Usage Examples
- UML Diagram
- Conclusion
📖 Overview & Purpose
File:
IrbyImaging.DbContext/Migrations/20250206152456_AddCostCodeType.Designer.cs
What is it?
- An auto‑generated EF Core “designer” file (model snapshot)
- Captures the shape of your EF Core model after the
AddCostCodeTypemigration - Used internally by EF Core to compute subsequent migrations
Why it matters
- Ensures EF Core knows exactly which tables/columns/keys exist
- Do not edit manually—any changes to your domain classes should be followed by
Add-Migration, which regenerates this snapshot
🛠 Dependencies & Technologies
| Technology | Version |
|---|---|
| .NET | 6.0+ |
| Entity Framework Core | 9.0.0 |
| Microsoft.EntityFrameworkCore.SqlServer | 9.0.0 |
| C# | 10+ |
| SQL Server | 2016+ |
🚀 Key Functional Areas
- Model Snapshot
BuildTargetModel(ModelBuilder modelBuilder)registers every entity
- Entity Configuration
- Defines tables, columns, keys, indexes
- Applies value conversions and identity columns
- Relationship Wiring
- Configures FKs, navigation properties & cascade rules
- Migration Tracking
- Acts as a baseline for future migrations
🗃️ Data Models & View Models
Note: This file only contains data model (domain) configurations.
There are no view models or API controllers here.
Key Domain Classes Included
- AccountBalances
- AccountLedger
- Asset (+ subclasses: Computer, MobileDevice, …)
- CostCode
- Job
- Employee
- …and many more (all under schema
"irby")
🔧 BuildTargetModel Method
Every EF Core migration designer file implements:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// 1) Annotations
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// 2) Entity configurations
modelBuilder.Entity("Namespace.ClassName", b =>
{
b.Property<CLRType>("PropertyName")
.HasColumnType("sqlType")
.ValueGeneratedOnAdd(); // e.g. GUID or Identity
b.HasKey("PrimaryKey");
b.HasIndex("ForeignKey");
b.ToTable("TableName", "schema");
});
// 3) Relationship wiring
modelBuilder.Entity("ClassA", b =>
{
b.HasOne("ClassB", "NavigationName")
.WithMany("CollectionName")
.HasForeignKey("ClassBId")
.OnDelete(DeleteBehavior.Cascade);
});
}
Purpose in EF Core Migrations
- Keeps a snapshot of your model so that EF can compute diffs when you run
Add-Migrationagain - Works in tandem with the
.csmigration file that contains theUp()andDown()SQL operations
🔎 Entity Spotlight: CostCode
The AddCostCodeType migration’s primary purpose was to add a new integer column CostCodeType to the CostCode table.
| Property | CLR Type | SQL Type | Notes |
|---|---|---|---|
CostCodeId |
Guid |
uniqueidentifier | PK, ValueGeneratedOnAdd |
CostCodeNumber |
string |
nvarchar(max) | |
CostCodeType |
int |
int | New column |
Name |
string |
nvarchar(max) | |
JobId |
Guid |
uniqueidentifier | FK → Job(JobId) |
modelBuilder.Entity("IrbyImaging.DomainClasses.CostCode", b =>
{
b.Property<Guid>("CostCodeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CostCodeNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("CostCodeType") // <-- New field
.HasColumnType("int");
b.Property<Guid>("JobId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("CostCodeId");
b.HasIndex("JobId");
b.ToTable("CostCode", "irby");
});
🔗 Relationships & Conventions
- Foreign Keys
Named{NavigationPropertyName}Id, configured with.HasForeignKey() - Cascade Delete
Applied to required relationships (.IsRequired()+.OnDelete(DeleteBehavior.Cascade)) - Schema
Most tables live in the"irby"schema; some use default (dbo) - Inheritance
Asset uses TPH (Table‑Per‑Hierarchy) with aDiscriminatorcolumn
🧑💻 Usage Examples
-
Apply the Migration
dotnet ef database update -
Querying the New Column
var code = await context.CostCodes.FindAsync(myCostCodeId); Console.WriteLine($"Cost Code Type: {code.CostCodeType}"); -
Filter by CostCodeType
var materialCodes = context.CostCodes .Where(cc => cc.CostCodeType == (int)CostCodeType.Material) .ToList();
📊 UML Diagram
+------------------+ 1 * +------------------+
| Job |<------------------------| CostCode |
+------------------+ +------------------+
| - JobId : Guid | | - CostCodeId:Guid|
| - JdeNumber: str | | - CostCodeNumber |
+------------------+ | - CostCodeType |
| - Name |
| - JobId : Guid |
+------------------+
📝 Conclusion
- AddCostCodeType.Designer.cs is a snapshot of your EF Core model after adding
CostCodeType. - Do not hand-edit—always update your C# domain classes + use
Add-Migration. - This file underpins EF’s ability to generate the correct SQL when you call
database updatein the future.
Enjoy clean migrations and a well‑tracked schema! 🎉
Generated by EF Core Tools · Do not modify manually