π Documentation: ChangePncIntFieldsToString.Designer.cs
π Table of Contents
- π File Metadata
- π Overview & Purpose
- βοΈ Migration Metadata & Context
- ποΈ BuildTargetModel Method
- ποΈ Key Entity: Pnc
- π€ EF Core Fluent API Configurations
- π Applying & Reverting the Migration
- π οΈ Dependencies & Technologies
- π Usage Examples
- π Conclusion
π File Metadata
| Attribute | Value |
|---|---|
| File Name | ChangePncIntFieldsToString.Designer.cs |
| Path | IrbyImaging.DbContext/Migrations/20240613154527_ChangePncIntFieldsToString |
| Generated By | Entity Framework Core Migrations (auto-generated) |
| EF Version | 7.0.7 |
| Date | 2024-06-13T15:45:27 |
π Overview & Purpose
This is an EF Core designer file that describes the target database model after applying the ChangePncIntFieldsToString migration.
- It does not contain the
Up()/Down()methods (those live in the non-designer file). - It provides a snapshot of all your domain entities, their properties, relationships, and table mappings.
- The migrationβs goal: Convert certain numeric Pnc fields to strings to support alphanumeric values.
βοΈ Migration Metadata & Context
[DbContext(typeof(IrbyContext))]
[Migration("20240613154527_ChangePncIntFieldsToString")]
partial class ChangePncIntFieldsToString
{
// ...
}
DbContext: Indicates this migration applies toIrbyContext.Migrationattribute: Uniquely identifies the migration by timestamp and name.- The partial class is paired with another file that implements
Up()/Down().
ποΈ BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// ... dozens of Entity configurations follow ...
#pragma warning restore 612, 618
}
- Purpose: Reconstructs the complete EF Core model as C# code.
- Annotations: Captures provider-specific settings (e.g., SQL Server identity columns).
- Entities: Each call to
modelBuilder.Entity(...)maps one CLR class.
ποΈ Key Entity: Pnc
This migration focuses on the Pnc table. Fields that were previously numeric IDs are now strings, enabling alphanumeric entries.
π Pnc Mapping Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.Pnc", b =>
{
b.Property<Guid>("PncId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CardNumber")
.HasColumnType("nvarchar(max)");
b.Property<string>("CustomerWorkOrderNumber")
.HasColumnType("nvarchar(max)");
b.Property<string>("DepartmentOrJobNumber") // Changed: int β string
.HasColumnType("nvarchar(max)");
b.Property<string>("EmployeeJdeAB") // Changed: int β string
.HasColumnType("nvarchar(max)");
// ... other properties ...
b.Property<string>("UnitNumber") // Changed: int β string
.HasColumnType("nvarchar(max)");
b.HasKey("PncId");
b.ToTable("Pnc", "irby");
});
π Pnc Property Summary
| Property | CLR Type | Column Type | Notes |
|---|---|---|---|
PncId |
Guid | uniqueidentifier | Primary key, identity-guid |
CustomerWorkOrderNumber |
string | nvarchar(max) | Was int, now string |
DepartmentOrJobNumber |
string | nvarchar(max) | Was int, now string |
EmployeeJdeAB |
string | nvarchar(max) | Was int, now string |
MCC |
int | int | Remains numeric |
TransactionDate |
DateTime | datetime2 | Posting date of transaction |
UnitNumber |
string | nvarchar(max) | Was int, now string |
πΌοΈ UML Diagram
@startuml
class Pnc {
+Guid PncId
+string CardNumber
+string CustomerWorkOrderNumber
+string DepartmentOrJobNumber
+string EmployeeJdeAB
+string FirstName
+string LastName
+int MCC
+string MerchantName
+DateTime PostingDate
+decimal SplitAmount
+string SubLedger
+string SubLedgerType
+string Subsidiary
+DateTime TransactionDate
+string TransactionId
+string UnitNumber
}
@enduml
π€ EF Core Fluent API Configurations
-
Identity Columns:
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);Applies default SQL Server identity strategy (
IDENTITY). -
Table & Schema:
b.ToTable("Pnc", "irby");Targets the
irby.Pncschema. -
Keys & Indexes:
b.HasKey("PncId"); // (Other indexes on FK properties appear across the model) -
Column Types: Explicitly set via
.HasColumnType(...)to ensure consistency.
π Applying & Reverting the Migration
- Add Migration
dotnet ef migrations add ChangePncIntFieldsToString - Apply to Database
dotnet ef database update - Revert
dotnet ef database update 20240613123456_PreviousMigrationName
Tip: The Designer file is automatically updated; do not hand-edit it.
π οΈ Dependencies & Technologies
| Technology | Version |
|---|---|
| .NET (C#) | 7.0 |
| Entity Framework Core | 7.0.7 |
| Microsoft.EntityFrameworkCore.SqlServer | 7.0.7 |
| SQL Server (Migrations Target) | 2016+ |
π Usage Examples
-
Inspect Model Snapshot
OpenChangePncIntFieldsToString.Designer.csto view the full model state. -
Customizing Migrations
If you need to tweak column types or data transformations, modify the non-designer migration file (withUp()/Down()). -
Data Seeding
You can add.HasData(...)calls inBuildTargetModelfor seeding, although we recommend usingUp().
π Conclusion
This designer file underpins the EF Core migration ChangePncIntFieldsToString, capturing a full snapshot of your data model after altering key Pnc fields from integers to strings. It ensures EF Core can compute diffs and apply database changes cleanly.
Keep it under source control but avoid manual edits, as it's regenerated every time you scaffold a migration.