πŸ“¦ Migration: ChangeFieldOfficeTable

File: IrbyImaging.DbContext/Migrations/20220516185008_ChangeFieldOfficeTable.Designer.cs
Generated: 05‑17‑2022 by kvamshi

πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. BuildTargetModel Method Explained
  5. Data Models & Entity Configurations
  6. Relationships & Constraints
  7. UML Diagram
  8. How to Use This Migration
  9. Sample Code Blocks & Usage
  10. Conclusion

πŸ” 1. Overview & Purpose

This Designer file is an auto-generated snapshot of your EF Core model at the point of the ChangeFieldOfficeTable migration.

  • What is it?
    • A model snapshot that MigrationBuilder uses to know how your schema should look after applying this migration.
  • Why is it here?
    • EF Core stores two parts of a migration:
      1. Up/Down logic (.cs file)
      2. Model snapshot (.Designer.cs file)
    • This ensures EF can detect future changes reliably.

πŸ”§ 2. Dependencies & Technologies

  • .NET 5.0
  • EntityFrameworkCore (v5.0.12)
    • Microsoft.EntityFrameworkCore
    • Microsoft.EntityFrameworkCore.Migrations
    • Microsoft.EntityFrameworkCore.Metadata
    • Microsoft.EntityFrameworkCore.Infrastructure
    • Microsoft.EntityFrameworkCore.Storage.ValueConversion
  • SQL Server (SqlServerValueGenerationStrategy.IdentityColumn)

🎯 3. Key Functional Areas

  • Configuration of all domain entities and their properties.
  • Definition of keys, indexes, table schemas, discriminators (for inheritance).
  • Relationships: foreign keys, navigation properties.
  • Schema specification (.HasAnnotation("Relational:MaxIdentifierLength", 128) & .ToTable("...", "irby")).

πŸ›  4. BuildTargetModel Method Explained

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    #pragma warning disable 612, 618
    modelBuilder
        .HasAnnotation("Relational:MaxIdentifierLength", 128)
        .HasAnnotation("ProductVersion", "5.0.12")
        .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);

    // ... many Entity <-> Table mappings ...
    #pragma warning restore 612, 618
}
  • ModelBuilder: the EF Core fluent API entry point for configuring your domain classes.
  • Each modelBuilder.Entity("Namespace.ClassName", b => { ... }) block:
    • b.Property<T>("PropName") β†’ maps a CLR property to a DB column.
    • b.HasKey("Id") β†’ primary key.
    • b.HasIndex("SomeProp") β†’ index (with optional .IsUnique()).
    • b.ToTable("TableName", "irby") β†’ specify table & schema.
    • b.HasDiscriminator<T>("Discriminator") β†’ table‑per‑hierarchy inheritance.

πŸ—‚ 5. Data Models & Entity Configurations

✨ FieldOffice Table Changes

This migration’s focus was the FieldOffice table.

Column Type Nullable Constraints
Id uniqueidentifier No PK, value generated on add
BusinessUnitName nvarchar(max) Yes β€”
BusinessUnitNumber nvarchar(max) Yes β€”
JdeNumber nvarchar(450) Yes Unique index (.HasIndex("JdeNumber").IsUnique())
ManagerId uniqueidentifier Yes FK β†’ Employee(Id)
Name nvarchar(max) Yes β€”
ProjectManagerId uniqueidentifier Yes FK β†’ Employee(Id)
SuperintendentId uniqueidentifier Yes FK β†’ Employee(Id)
modelBuilder.Entity("IrbyImaging.DomainClasses.FieldOffice", b =>
{
    b.Property<Guid>("Id")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");

    b.Property<string>("BusinessUnitName").HasColumnType("nvarchar(max)");
    b.Property<string>("BusinessUnitNumber").HasColumnType("nvarchar(max)");
    b.Property<string>("JdeNumber").HasColumnType("nvarchar(450)");

    b.Property<Guid?>("ManagerId").HasColumnType("uniqueidentifier");
    b.Property<string>("Name").HasColumnType("nvarchar(max)");
    b.Property<Guid?>("ProjectManagerId").HasColumnType("uniqueidentifier");
    b.Property<Guid?>("SuperintendentId").HasColumnType("uniqueidentifier");

    b.HasKey("Id");
    b.HasIndex("JdeNumber").IsUnique().HasFilter("[JdeNumber] IS NOT NULL");
    b.HasIndex("ManagerId");
    b.HasIndex("ProjectManagerId");
    b.HasIndex("SuperintendentId");
    b.ToTable("FieldOffice", "irby");
});

πŸ”Ž Other Key Entities (Summary)

Below is a sampling; the file configures 25+ tables.

  • Asset Hierarchy
    • Base: Asset (Discriminator="Asset")
    • Derived: Computer, DeskPhone, MobileDevice, Monitor, OfficePrinter, Dock, Printer, SafetyEquipment, NetworkEquipment
  • AssetModel & AssetModelDetail
  • Employee, Job, FieldOffice
  • BillingInvoice, **CarrierType/CarrierTypeDetail`
  • CovidTestData, DocumentImage, TempDocumentData, IPMMigration
  • GLTypeDetail, GeneralLedger
  • Ticket & Update
  • ODS_Staging tables: ODSEmployee, ODSJob

πŸ”— 6. Relationships & Constraints

  • One-to-Many:
    • FieldOffice β†’ Asset (FieldOffice.Assets)
    • Employee β†’ Asset (Employee.Assets)
    • AssetModel β†’ Asset (AssetModel β†’ Asset)
    • Job β†’ Employee (Job.Employees)
    • Ticket β†’ Update (Ticket.Updates)
  • Many-to-One:
    • Asset β†’ FieldOffice, AssetModel, Employee
    • FieldOffice β†’ Employee (Manager, ProjectManager, Superintendent)
  • Cascade Deletes: configured for required FKs
modelBuilder.Entity("IrbyImaging.DomainClasses.FieldOffice", b =>
{
    b.HasOne("IrbyImaging.DomainClasses.Employee", "Manager")
     .WithMany()
     .HasForeignKey("ManagerId");
     // … similarly for ProjectManager & Superintendent
});

πŸ“Š 7. UML Diagram

erDiagram
    FIELD_OFFICE ||--o{ ASSET                : "hosts"
    EMPLOYEE    ||--o{ ASSET                 : "owns"
    ASSET_MODEL ||--o{ ASSET                 : "models"
    FIELD_OFFICE }|..|| EMPLOYEE   : Manager
    FIELD_OFFICE }|..|| EMPLOYEE   : ProjectManager
    FIELD_OFFICE }|..|| EMPLOYEE   : Superintendent
    TICKET      ||--o{ UPDATE                : "updates"

πŸš€ 8. How to Use This Migration

  1. Apply to your database:
    dotnet ef database update 20220516185008_ChangeFieldOfficeTable
    
  2. Rollback to previous migration:
    dotnet ef database update <PreviousMigrationName>
    
  3. Inspect your schema changes:
    • Use SQL Server Management Studio or dotnet ef migrations script.

πŸ’‘ 9. Sample Code Blocks & Usage

Adding a New FieldOffice in C#

using (var context = new IrbyContext())
{
    var office = new FieldOffice {
        BusinessUnitName   = "Engineering",
        BusinessUnitNumber = "ENG-001",
        JdeNumber          = "100234",
        Name               = "North Field",
        ManagerId          = managerGuid
    };
    context.FieldOffices.Add(office);
    context.SaveChanges();
}

Querying Assets by FieldOffice

var assetsInNorthField = context.Assets
    .Include(a => a.FieldOffice)
    .Where(a => a.FieldOffice.JdeNumber == "100234")
    .ToList();

🏁 10. Conclusion

πŸ‘ This Designer file is a snapshot of your EF Core model post‑migration.

  • It ensures consistency for future migrations.
  • Any change in your domain classes will generate a new .Designer.cs to reflect updates.
  • Tip: Don’t manually edit this file; let EF Core maintain it.

Happy coding! ✨