📖 Table of Contents
- Overview & Purpose
- Entity Framework Core Migrations
ChangePncIntFieldsToString2.Designer.csin Context- Key Functional Areas
- Focus: Pnc Entity Type Change
- Dependencies & Technologies
- Using & Running the Migration
- Sample Code Snippets
- UML Class Diagram (Excerpt)
- Conclusion
1. Overview & Purpose
🎯 ChangePncIntFieldsToString2.Designer.cs is an auto‑generated Entity Framework Core (EF Core) migration snapshot for the 20240613160449_ChangePncIntFieldsToString2 migration. It defines the target model (schema) after the migration executes, including all tables, columns, keys, indexes, and relationships.
Why this matters:
- Ensures EF Core can compare your C# model to the database schema
- Supports
dotnet ef database updateand rollback scenarios - Captures your domain classes’ shape for versioned schema evolution
2. Entity Framework Core Migrations
- Migrations track incremental changes to your model—adding/removing tables, renaming columns, changing types, etc.
- Each migration folder typically has three files:
*.cs(the up/down logic)*.Designer.cs(model snapshot)*.resx(optional resources)
The Designer file is not edited by hand; it’s generated by EF Core to record the model state after the migration.
3. ChangePncIntFieldsToString2.Designer.cs in Context
IrbyImaging.DbContext/
└── Migrations/
├── 20240613160449_ChangePncIntFieldsToString2.cs
├── 20240613160449_ChangePncIntFieldsToString2.Designer.cs ← *This file*
└── MigrationsHistoryTable…
- Namespace:
IrbyImaging.DbContext.Migrations - DbContext:
IrbyContext - Migration ID:
20240613160449_ChangePncIntFieldsToString2
4. Key Functional Areas
4.1 BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// Overall model annotations
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// Entities & mappings follow…
}
- Purpose: Construct the EF Core
ModelBuilderrepresentation of your domain model as it should exist after applying this migration.
4.2 Entity Definitions & Mappings
- Entity: Represents a table in the
"irby"schema (default). - Property Mapping: Column type, nullability, max-length.
- Key Mapping:
HasKey(),ValueGeneratedOnAdd(). - Indexes:
HasIndex().IsUnique().HasFilter().
Example:
| Entity | Table | Key | Sample Property |
|---|---|---|---|
Pnc |
irby.Pnc |
PncId |
CardNumber (string) |
AssetModel |
irby.AssetModel |
Id |
Name (string) |
Employee |
irby.Employee |
EmployeeId |
JdeNumber (unique nvarchar(450)) |
4.3 Relationships & Navigation Properties
- EF Core fluent API defines one‑to‑many, many‑to‑many, etc.
- Example:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { b.HasOne("FieldOffice") .WithMany("Assets") .HasForeignKey("FieldOfficeId"); });
5. Focus: Pnc Entity Type Change
This migration is named ChangePncIntFieldsToString2, indicating a type alteration in the Pnc table:
| Before | After |
|---|---|
| DepartmentOrJobNumber: int | DepartmentOrJobNumber: string |
| EmployeeJdeAB: int | EmployeeJdeAB: string |
🎉 Result in Designer:
modelBuilder.Entity("IrbyImaging.DomainClasses.Pnc", b => {
b.Property<Guid>("PncId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// All numeric fields converted to string
b.Property<string>("DepartmentOrJobNumber").HasColumnType("nvarchar(max)");
b.Property<string>("EmployeeJdeAB").HasColumnType("nvarchar(max)");
/* …other properties… */
b.HasKey("PncId");
b.ToTable("Pnc", "irby");
});
Why: Converting int fields to string allows capturing leading zeros, alphanumeric codes, or avoiding overflow issues.
6. Dependencies & Technologies
- .NET 7.0
- C# 11
- Entity Framework Core 7.0.7
- SQL Server (relational mappings via
UseIdentityColumns)
7. Using & Running the Migration
- Add Migration (already done):
dotnet ef migrations add ChangePncIntFieldsToString2 - Update Database:
dotnet ef database update 20240613160449_ChangePncIntFieldsToString2 - Rollback (to previous migration):
dotnet ef database update <PreviousMigrationName>
8. Sample Code Snippets
8.1 Inspecting the Pnc Entity
public class Pnc
{
public Guid PncId { get; set; }
public string CardNumber { get; set; }
public string DepartmentOrJobNumber { get; set; } // <— now string
public string EmployeeJdeAB { get; set; } // <— now string
public DateTime TransactionDate { get; set; }
public decimal SplitAmount { get; set; }
// …other properties…
}
8.2 Fluent Configuration Excerpt
modelBuilder.Entity<Pnc>(entity =>
{
entity.ToTable("Pnc", "irby");
entity.HasKey(e => e.PncId);
entity.Property(e => e.DepartmentOrJobNumber)
.HasColumnType("nvarchar(max)");
entity.Property(e => e.EmployeeJdeAB)
.HasColumnType("nvarchar(max)");
});
9. UML Class Diagram (Excerpt)
classDiagram
class Pnc {
+Guid PncId
+string CardNumber
+string DepartmentOrJobNumber
+string EmployeeJdeAB
+DateTime TransactionDate
+decimal SplitAmount
}
class Asset {
+Guid Id
+string Discriminator
+string SerialNumber
// …
}
Asset <|-- Computer
Asset <|-- MobileDevice
Pnc ..> Asset : uses?
10. Conclusion
This Designer snapshot is critical for EF Core to maintain a consistent model‑to‑database mapping. The ChangePncIntFieldsToString2 migration primarily transforms selected integer fields in the Pnc entity into strings for greater flexibility in storing alphanumeric identifiers. All other entities, tables, and relationships are recorded here to ensure smooth schema evolution and version control.
💾 Always check this file into source control to preserve your complete migration history!