π IrbyImaging.DbContext Migrations
20250212153204_ChangeTypeOnClassNumber.Designer.cs
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Entity Snapshots & Data Models
4.1 JobClassificationΒ β ClassNumber Change
4.2 Asset Hierarchy & Discriminators
4.3 Relationships & Navigation Properties - Helper Methods & Utilities
- Usage & Examples
- UML DiagramΒ β Selected Model
- Conclusion
π Overview & Purpose
This auto-generated EF Core migration designer file captures the target model snapshot for the migration named:
ChangeTypeOnClassNumber
Timestamp:2025-02-12 15:32:04
When you add or update an EF Core migration, the .Designer.cs file is generated to record the entire state of your DbContext model after applying that migration.
- It drives up/down diff calculations
- Ensures subsequent migrations know the βbeforeβ and βafterβ shapes
- It is not meant to be edited manually
β Important:
Always use
dotnet ef migrations addorUpdate-Databaserather than handcrafting this.
π οΈ Dependencies & Technologies
| Package | Version | Purpose |
|---|---|---|
| Microsoft.EntityFrameworkCore | β (9.0.0) | ORM base |
| Microsoft.EntityFrameworkCore.Relational | 9.0.0 | Relational database support |
| Microsoft.EntityFrameworkCore.SqlServer | 9.0.0 | SQLΒ Server-specific functionality |
| Microsoft.EntityFrameworkCore.Infrastructure | 9.0.0 | Internal EF infrastructure |
| Microsoft.EntityFrameworkCore.Metadata | 9.0.0 | Model metadata |
| Microsoft.EntityFrameworkCore.Storage.ValueConversion | 9.0.0 | Conversion of CLR types β store types |
- Target: .NETΒ 7+ / .NETΒ 8
- Database: SQLΒ Server (identity columns used)
- Annotations:
ProductVersion = "9.0.0"Relational:MaxIdentifierLength = 128
π§© Key Functional Areas
-
Global Model Configuration
modelBuilder.HasAnnotation(...)SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
-
Entity Type Definitions
modelBuilder.Entity("Namespace.DomainClass", b => { ... })- Property mappings:
.Property<T>("Name").HasColumnType("...") - Keys:
.HasKey("PrimaryKeyProperty") - Tables & Schemas:
.ToTable("TableName", "SchemaName") - Indexes:
.HasIndex("Property").IsUnique()
-
Inheritance / Discriminators
- TableβPerβHierarchy (TPH) patterns
.HasDiscriminator().HasValue("TypeName")
-
Relationships & Navigation Properties
.HasOne(...).WithMany(...).HasForeignKey("...")- OnDelete behaviors, cascading rules
ποΈ Entity Snapshots & Data Models
This migration snapshot includes over 100 domain classes. Below we highlight critical or changed parts.
4.1 JobClassificationΒ β ClassNumber Change
π§ Migration Goal: Change the CLR type of ClassNumber
from int β string
modelBuilder.Entity("IrbyImaging.DomainClasses.JobClassification", b =>
{
b.Property<Guid>("JobClassificationId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// π Changed here:
b.Property<string>("ClassNumber")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name").HasColumnType("nvarchar(max)");
b.Property<Guid>("JobId").HasColumnType("uniqueidentifier");
// β¦ other properties β¦
b.HasKey("JobClassificationId");
b.HasIndex("JobId");
b.ToTable("JobClassification", "irby");
});
- Before: ClassNumber mapped to
int (int, non-nullable) - After: ClassNumber mapped to
string (nvarchar(max), non-nullable)
This enables alphanumeric codes, leading zeros, or flexible formatting.
4.2 Asset Hierarchy & Discriminators
The Asset entity uses TPH with a Discriminator column to store subtypes:
| CLR Type | Discriminator | Notes |
|---|---|---|
| Asset | "Asset" | Base class |
| Computer | "Computer" | Adds CpsNumber, OperatingSystemId |
| MobileDevice | "MobileDevice" | Imei, PhoneNumber, Carrier, Type |
| ... | ... | ... |
Example: MobileDevice mapping
modelBuilder.Entity("IrbyImaging.DomainClasses.MobileDevice", b => {
b.HasBaseType("IrbyImaging.DomainClasses.Asset");
b.Property<string>("Imei")
.HasColumnType("nvarchar(450)");
b.HasIndex("Imei")
.IsUnique()
.HasFilter("[Imei] IS NOT NULL");
b.ToTable("Asset", "irby");
b.HasDiscriminator().HasValue("MobileDevice");
});
4.3 Relationships & Navigation Properties
Most entities are wired via foreign keys:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
b.HasOne("IrbyImaging.DomainClasses.FieldOffice", "FieldOffice")
.WithMany("Assets")
.HasForeignKey("FieldOfficeId");
b.HasOne("IrbyImaging.DomainClasses.AssetModel", "Model")
.WithMany()
.HasForeignKey("ModelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("FieldOffice");
b.Navigation("Model");
});
- OneβtoβMany: e.g.,
FieldOfficeβ manyAsset - Cascade Delete: configured for certain critical dependencies
- Indices: created on FK columns to speed up joins
π οΈ Helper Methods & Utilities
In this .Designer.cs youβll notice:
-
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
β Configures all integer keys to use SQLΒ Server IDENTITY by default. -
#pragma warning disable 612, 618
β Suppresses deprecation warnings if your domain classes still use older APIs.
There are no custom extension methods hereβitβs pure EF Core scaffolding.
π‘ Usage & Examples
-
Applying this Migration
dotnet ef database update 20250212153204_ChangeTypeOnClassNumberThis will ALTER the
JobClassificationtable, converting itsClassNumbercolumn tonvarchar(max). -
Reverting
dotnet ef database update <Previous_Migration_Name> -
Inspecting the SQL
dotnet ef migrations script 20250212153204_ChangeTypeOnClassNumberβ See the exact
ALTER TABLEcommands.
π UML DiagramΒ β Selected Model
Below is a simplified UML class diagram illustrating the Job β JobClassification relationship:
βββββββββββββββββββββ 1 * ββββββββββββββββββββββββββ
β Job ββββββββββββββββββββββββΆ β JobClassification β
βββββββββββββββββββββ€ ββββββββββββββββββββββββββ€
β β’ JobId : Guid β β β’ JobClassificationId β
β β’ Name : string β β β’ ClassNumber : string β
β β’ JdeNumber : str β β β’ CostCodeNumber : int β
β β β β’ Name : string β
βββββββββββββββββββββ ββββββββββββββββββββββββββ
- A Job can have multiple JobClassification entries.
- Cascade delete ensures if a Job is removed, its classifications go, too.
π Conclusion
This ChangeTypeOnClassNumber.Designer.cs is your snapshot of the entire EF Core model after altering the ClassNumber property on JobClassification from an integer to a string.
- It guarantees consistency across migrations
- Autoβgenerated: avoid manual edits!
- Key takeaway: Your domain is now flexible to alphanumeric class codes π
Happy coding! π