πŸ“„ Documentation: ChangePncIntFieldsToString.Designer.cs


πŸ“š Table of Contents

  1. πŸ“ File Metadata
  2. πŸ” Overview & Purpose
  3. βš™οΈ Migration Metadata & Context
  4. πŸ—οΈ BuildTargetModel Method
  5. πŸ—ƒοΈ Key Entity: Pnc
  6. 🀝 EF Core Fluent API Configurations
  7. πŸ”„ Applying & Reverting the Migration
  8. πŸ› οΈ Dependencies & Technologies
  9. πŸ“š Usage Examples
  10. πŸ“ 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 to IrbyContext.
  • Migration attribute: 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.Pnc schema.

  • 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

  1. Add Migration
    dotnet ef migrations add ChangePncIntFieldsToString
    
  2. Apply to Database
    dotnet ef database update
    
  3. 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
    Open ChangePncIntFieldsToString.Designer.cs to view the full model state.

  • Customizing Migrations
    If you need to tweak column types or data transformations, modify the non-designer migration file (with Up()/Down()).

  • Data Seeding
    You can add .HasData(...) calls in BuildTargetModel for seeding, although we recommend using Up().


πŸ“ 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.