📑 Migration Designer Documentation

File: IrbyImaging.DbContext/Migrations/20230802163348_RemoveColumnFromRole.Designer.cs


📖 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Model Snapshot & BuildTargetModel
  5. Data Models & Entity Mappings
  6. Relationships & Navigation Properties
  7. Inheritance & Discriminators (TPH)
  8. Indexes, Keys & Constraints
  9. Usage & Examples
  10. Conclusion

1. Overview & Purpose

This auto-generated designer file belongs to an Entity Framework Core migration named RemoveColumnFromRole (timestamp 20230802163348).

  • 🔍 What it is: A “model snapshot” that EF Core uses to understand your database schema after the migration has been applied.
  • 🎯 What it does: Defines the complete set of entities, their properties, keys, indexes, relationships, and table mappings — reflecting the schema state after the Role column removal.
  • 🚧 When it’s used: During dotnet ef database update or when scaffolding future migrations, EF compares this snapshot against the current model to generate diffs.

Note: You should not manually edit this file. All changes should be made via Add-Migration / dotnet ef migrations add commands and your DbContext classes.


2. Dependencies & Technologies

Technology / Package Version Purpose
.NET SDK ≥ 7.0 Target framework
Microsoft.EntityFrameworkCore 7.0.7 Core ORM
Microsoft.EntityFrameworkCore.SqlServer 7.0.7 SQL Server provider
Microsoft.EntityFrameworkCore.Design 7.0.7 Migrations & tooling
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.7" />

3. Key Functional Areas

  1. BuildTargetModel
    • Entry point that configures the entire model via the ModelBuilder.
  2. Entity Configuration
    • Defines each entity’s properties, column types, keys, and indexes.
  3. Relationships
    • Configures foreign‑key relationships & navigation properties.
  4. Inheritance Mapping (TPH)
    • Uses a discriminator on the Asset table for derived types (e.g., Computer, MobileDevice).
  5. Annotations & Provider Settings
    • Product version (7.0.7), max identifier length (128), and SQL Server identity columns.

4. Model Snapshot & BuildTargetModel

[DbContext(typeof(IrbyContext))]
[Migration("20230802163348_RemoveColumnFromRole")]
partial class RemoveColumnFromRole
{
    protected override void BuildTargetModel(ModelBuilder modelBuilder)
    {
        // 1️⃣ Provider‑wide annotations
        modelBuilder
            .HasAnnotation("ProductVersion", "7.0.7")
            .HasAnnotation("Relational:MaxIdentifierLength", 128);
        SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

        // 2️⃣ Entity registrations …
        modelBuilder.Entity("IrbyImaging.DomainClasses.Role", b => { … });
        modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { … });
        // … plus dozens of other domain classes
    }
}
  • Line-by-line
    1. Annotations: Stores EF Core version and SQL Server conventions.
    2. UseIdentityColumns: Enables IDENTITY(1,1) by default.
    3. Entity(...): Reconfigures each CLR type as a table.

5. Data Models & Entity Mappings

Below are two representative entities to illustrate the pattern. All other entities follow similar conventions.

Sample Entity: Role

Aspect Description
CLR Type IrbyImaging.DomainClasses.Role
Table irby.Role
Primary Key RoleId (uniqueidentifier, value‑generated)
Columns Name, Description, AddedBy, AddedDate, ModifiedBy, ModifiedDate, IsDeleted
Removed Column (This migration removed a column here — e.g., SomeObsoleteField)
modelBuilder.Entity("IrbyImaging.DomainClasses.Role", b =>
{
    b.Property<Guid>("RoleId")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");

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

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

    b.Property<bool>("IsDeleted")
     .HasColumnType("bit");

    b.Property<string>("AddedBy").HasColumnType("nvarchar(max)");
    b.Property<DateTime>("AddedDate").HasColumnType("datetime2");
    b.Property<string>("ModifiedBy").HasColumnType("nvarchar(max)");
    b.Property<DateTime>("ModifiedDate").HasColumnType("datetime2");

    b.HasKey("RoleId");
    b.ToTable("Role", "irby");
});

Tip: The missing property in this block corresponds to the column removed by your migration.


Sample Entity: Asset

Aspect Description
CLR Type IrbyImaging.DomainClasses.Asset
Table irby.Asset
Primary Key Id (uniqueidentifier)
Discriminator TPH — base type for Computer, Monitor, etc.
Foreign Keys FieldOfficeId, ModelId (required), OwnerId
Indexes Index on each FK
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
    b.Property<Guid>("Id")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");

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

    b.Property<int>("ModelId")
     .HasColumnType("int");

    b.Property<Guid?>("FieldOfficeId").HasColumnType("uniqueidentifier");
    b.Property<Guid?>("OwnerId").HasColumnType("uniqueidentifier");

    // … other common 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();
});

6. Relationships & Navigation Properties

The designer configures one‑to‑many and many‑to‑one relationships, for example:

Principal Entity Dependent Entity FK Property Delete Behavior
AssetModel Asset ModelId Cascade
Employee Asset OwnerId (Default)
Role LinkUserRole RoleId Cascade
TimeEntryType TimeSheetEntry TimeEntryTypeId Cascade
Ticket Update TicketId Cascade
modelBuilder.Entity("IrbyImaging.DomainClasses.LinkUserRole", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.Employee", "User")
     .WithMany() // Employee → LinkUserRole
     .HasForeignKey("EmployeeId")
     .OnDelete(DeleteBehavior.Cascade)
     .IsRequired();

    b.HasOne("IrbyImaging.DomainClasses.Role", "Role")
     .WithMany() // Role → LinkUserRole
     .HasForeignKey("RoleId")
     .OnDelete(DeleteBehavior.Cascade)
     .IsRequired();
});

7. Inheritance & Discriminators (TPH)

Entity Framework Core uses Table‑Per‑Hierarchy for the Asset base type:

  • Discriminator column: Discriminator (nvarchar(max), stores CLR type names).
  • Derived types:
    • Computer
    • DeskPhone
    • Dock
    • MobileDevice
    • Monitor
    • NetworkEquipment
    • OfficePrinter
    • Printer
    • SafetyEquipment
// Example: Computer
modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b =>
{
    b.HasBaseType("IrbyImaging.DomainClasses.Asset");
    b.Property<string>("AssetNumber").HasColumnType("nvarchar(max)");
    b.Property<int>("OperatingSystemId").HasColumnType("int");
    b.HasIndex("OperatingSystemId");
    b.ToTable("Asset", "irby");
    b.HasDiscriminator().HasValue("Computer");
});

8. Indexes, Keys & Constraints

  • Primary Keys: HasKey(...) on all Id‑style fields.
  • Indexes:
    • Foreign keys (.HasIndex("FieldOfficeId"))
    • Unique indexes (e.g., Employee.JdeNumber, Job.JdeNumber)
  • Column types: Explicitly set via .HasColumnType("nvarchar(max)"), "datetime2", "decimal(18,2)", etc.

9. Usage & Examples

9.1. Generating This Migration

dotnet ef migrations add RemoveColumnFromRole \
    --context IrbyContext \
    --output-dir DbContext/Migrations

9.2. Applying Migrations

dotnet ef database update --context IrbyContext

9.3. Rolling Back

dotnet ef database update 20230701000000  # the previous migration

10. Conclusion

This designer file is the canonical EF Core model snapshot after executing the RemoveColumnFromRole migration. It documents:

  • ✅ All entities in IrbyImaging.DomainClasses
  • ✅ Table mappings, column types, and keys
  • ✅ Relationships, navigation properties, and delete behaviors
  • ✅ TPH inheritance for the Asset hierarchy

Keep this file synchronized with your model classes by always using EF Core’s migration commands. 🚀


Happy Coding! 👩‍💻👨‍💻