📄 Migration: 20230706201721_DropForeignKeys.Designer.cs

Auto‑generated by Entity Framework Core
DbContext: IrbyContext
Migration: DropForeignKeys
EF Core Version: 7.0.7


📑 Table of Contents

  1. 🎯 Overview & Purpose
  2. 🛠️ Dependencies & Technologies
  3. 🗂️ Key Functional Areas
    • 3.1 Migration Metadata
    • 3.2 BuildTargetModel Method
    • 3.3 Entity Configuration
    • 3.4 Relationships & Constraints
    • 3.5 Inheritance (TPH) & Discriminator Mapping
  4. 📊 Data Models Reference
  5. 🔗 Indices & Keys
  6. 🖼️ Sample UML Diagram
  7. 👩‍💻 Usage & Examples
  8. 🚀 Conclusion

🎯 1. Overview & Purpose

This file is the designer portion of the DropForeignKeys EF Core migration. Its role is to capture a snapshot of your model after the migration has been applied, so that EF Core can:

  • Generate accurate Up/Down scripts.
  • Compare the current model to the previous snapshot.
  • Scaffold future migrations reliably.

Note:

  • Do not modify this file manually—it is re‑generated on each dotnet ef migrations add ....
  • For the actual schema changes (Dropping/Adding FKs), see 20230706201721_DropForeignKeys.cs (the code‑behind).

🛠️ 2. Dependencies & Technologies

Technology Version/Notes
.NET 7.0.7
Entity Framework Core Microsoft.EntityFrameworkCore (v7)
Database Provider Microsoft.EntityFrameworkCore.SqlServer
Fluent API modelBuilder & IEntityTypeBuilder<TEntity>
Value Conversion Support ValueConverter, UseIdentityColumns

🗂️ 3. Key Functional Areas

3.1 Migration Metadata

[DbContext(typeof(IrbyContext))]
[Migration("20230706201721_DropForeignKeys")]
partial class DropForeignKeys { … }
  • [DbContext]: Associates this migration with the IrbyContext.
  • [Migration("…")]: Assigns a unique identifier (timestamp + name).

3.2 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);

    // **Entity definitions follow…**

    #pragma warning restore 612, 618
}
  • Purpose: Reconstructs the entire EF Core model (entities, properties, keys, relationships, table mappings) at this migration point.
  • Annotations:
    • ProductVersion: EF Core version
    • MaxIdentifierLength: Limits for SQL Server
  • SQL Server Identities: UseIdentityColumns configures default identity strategy.

3.3 Entity Configuration

For each domain class, EF Core generates:

  1. Properties: CLR type → column type
  2. Keys: .HasKey(...)
  3. Indices: .HasIndex(...)
  4. Table Mapping: .ToTable("TableName", "Schema")
  5. Discriminator (for inheritance)

Example: IrbyImaging.DomainClasses.Asset

modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
    b.Property<Guid>("Id")
      .ValueGeneratedOnAdd()
      .HasColumnType("uniqueidentifier");

    b.Property<string>("Category")
      .IsRequired()
      .HasColumnType("nvarchar(max)");

    // … other properties …

    b.HasKey("Id");
    b.HasIndex("FieldOfficeId");
    b.HasIndex("ModelId");
    b.HasIndex("OwnerId");

    b.ToTable("Asset", "irby");
    b.HasDiscriminator<string>("Discriminator")
     .HasValue("Asset");
    b.UseTphMappingStrategy();
});

3.4 Relationships & Constraints

At the bottom of BuildTargetModel, navigation properties are wired up:

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.HasOne("IrbyImaging.DomainClasses.Employee", "Owner")
     .WithMany("Assets")
     .HasForeignKey("OwnerId");
});
  • HasOne / WithMany: Configures FK relationships.
  • OnDelete(DeleteBehavior.Cascade): Enforces cascade delete.
  • Dropped FKs: This migration likely removed some HasForeignKey(...) calls in the Up method, but the snapshot here is the resulting model.

3.5 Inheritance (TPH) & Discriminator Mapping

Assets use Table‑per‑Hierarchy (TPH):

CLR Type Discriminator Value
Asset (base) "Asset"
Computer "Computer"
DeskPhone "DeskPhone"
Dock "Dock"
MobileDevice "MobileDevice"
Monitor "Monitor"
NetworkEquipment "NetworkEquipment"
OfficePrinter "OfficePrinter"
Printer "Printer"
SafetyEquipment "SafetyEquipment"

All are stored in the irby.Asset table and distinguished by the Discriminator column.


📊 4. Data Models Reference

Below is a summary of the primary entities configured in this snapshot:

Entity Class Table (Schema) PK Notes
Asset Asset (irby) Id : GUID TPH base & discriminator
AssetHistory AssetHistory (irby) Id : GUID History tracking
AssetModel AssetModel (irby) Id : int FK→Manufacturer
AssetModelDetail AssetModelDetail Id : int Additional model details (opt.)
BillingInvoice BillingInvoice (irby) Id : GUID Billing subsystem
BlobData BlobData (irby) BlobDataId : GUID Temporary images
CarrierType & CarrierTypeDetail CarrierType (irby) Id : GUID Shipping/carrier metadata
CovidTestData CovidTestData (irby) CovidTestDataId Custom PK name
Customer Customer (irby) Id : GUID Lightweight lookup
DocumentAttribute, Category, Type Various Id : GUID Document‐management config
DocumentImage DocumentImage (irby) DocumentImageId Scanned/OCR documents
Employee Employee (irby) Id : GUID FK→Job (CurrentJobId)
FieldOffice FieldOffice (irby) Id : GUID FK→Employee (Manager, PM, Sup’t)
GeneralLedger & GLTypeDetail Various Id : GUID Financial reference data
IPMMigration, IrbyForms, LytxTemplate Various GUID Batch‐imported images/data
Job Job (irby) Id : GUID FK→JdeNumber (unique)
Manufacturer AssetManufacturer Id : int Tied to AssetModel
ODSEmployee, ODSJob ODS Staging tables custom keys ETL staging
OperatingSystem OperatingSystem (irby) Id : int Mapped by Computer & SafetyEquipment
RequestOption RequestOption (irby) Id : GUID Lookup for UI Options
State State (irby) Id : GUID US state codes
TempDocumentData TempDocumentData TempDocumentDataId Staging for OCR
Ticket & Update Ticket (irby) Id : GUID Support ticketing with updates
TimeEntryType, TimeSheetEntry Various Id : GUID Timesheet subsystem
Vehicle, Issue Various Id : GUID Light‐weight domain support

🔎 Tip: You can cross‑reference each entity’s .ToTable(...) & .HasKey(...) calls in the BuildTargetModel method for full detail.


🔗 5. Indices & Keys

  • Primary Keys: Generated via .HasKey(...).
  • Identity Columns:
    • Tables with int PK use UseIdentityColumn.
  • Unique Indices:
    • Employee.JdeNumber
    • FieldOffice.JdeNumber
    • Job.JdeNumber
    • MobileDevice.Imei

🖼️ 6. Sample UML Diagram (Mermaid)

classDiagram
    %% Entities
    Asset <|-- Computer
    Asset <|-- DeskPhone
    Asset <|-- Dock
    Asset <|-- MobileDevice
    Asset <|-- Monitor
    Asset <|-- NetworkEquipment
    Asset <|-- OfficePrinter
    Asset <|-- Printer
    Asset <|-- SafetyEquipment

    Asset "1" o-- "0..*" FieldOffice : FieldOffice
    Asset "1" o-- "1" AssetModel  : Model
    Asset "1" o-- "0..*" Employee  : Owner

    AssetModel "1" o-- "0..*" AssetModelDetail : AssetsModelDetail
    AssetModel "1" o-- "0..*" Asset           : (TPH)

    Employee "1" o-- "0..*" Asset  : Assets
    Employee "1" o-- "0..1" Job    : CurrentJob

    FieldOffice "1" o-- "0..*" Asset : Assets
    FieldOffice "1" o-- "0..1" Employee : Manager
    FieldOffice "1" o-- "0..1" Employee : ProjectManager
    FieldOffice "1" o-- "0..1" Employee : Superintendent

Note: Copy the above into a Mermaid‑enabled Markdown viewer.


👩‍💻 7. Usage & Examples

Applying the Migration

# Generate SQL script:
dotnet ef migrations script 20230706201721_DropForeignKeys

# Update the database:
dotnet ef database update 20230706201721_DropForeignKeys

Inspecting Model Snapshot

If you want to see the state of your model at a given migration, inspect the BuildTargetModel in the corresponding .Designer.cs file. It shows:

  • All table mappings
  • All property configurations
  • The shape of relationships

🚀 8. Conclusion

This DropForeignKeys.Designer.cs file is the blueprint EF Core uses to know “what the world looks like” after the DropForeignKeys migration is applied. It ensures:

  • Consistency between code and database during migrations
  • Accurate Up/Down scripts
  • Reliable future scaffolding

⭐️ Best Practices

  • Let EF Core auto‑generate and maintain this file.
  • Check your main migration (.cs) for the actual DDL changes.
  • Use dotnet ef migrations add/ remove to evolve your schema safely.

Happy Coding! 🚀