📑 Documentation for 20220607180629_TablesForLegalImaging.Designer.cs

Assembly: IrbyImaging.DbContext
Migration: 20220607180629_TablesForLegalImaging
Author: kvamshi
Created: 06‑07‑2022
Last Modified: 06‑07‑2022


Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Entities & Tables Summary
  4. Schema Details: Selected Entities
  5. Relationships & UML Diagram
  6. Dependencies & Technologies
  7. Applying This Migration
  8. Sample Code Snippets
  9. Conclusion

1. Overview & Purpose

This file is the auto‑generated designer portion of an Entity Framework Core migration:

  • It belongs to the IrbyImaging.DbContext.Migrations namespace.
  • It inherits from Migration and carries the attribute [DbContext(typeof(IrbyContext))].
  • The BuildTargetModel method defines the complete EF Core model snapshot at the point of this migration.
  • EF Core uses this snapshot to compute schema diffs and generate/up‑date database tables in SQL Server.

🛠️ Why it exists?
When you run dotnet ef migrations add TablesForLegalImaging, EF Core scaffolds two files:

  1. 20220607180629_TablesForLegalImaging.cs – the migration operations (Up/Down).
  2. 20220607180629_TablesForLegalImaging.Designer.cs – the model snapshot (this file).

2. Key Functional Areas

  1. Annotation Setup
    • Sets max identifier length, product version, SQL Server identity strategy.
  2. Entity Configuration
    • Defines properties, keys, indexes, table names (with schema "irby"), and discriminators for inheritance.
  3. Relationship Mapping
    • Configures foreign keys and navigation properties between entities.
  4. Inheritance (TPH)
    • Several subtypes (e.g., Computer, MobileDevice) derive from the base Asset entity using a discriminator column.

3. Entities & Tables Summary

Below is a high‑level list of entities defined in this migration. For full details, see the code!

Entity (Class) Table Name Schema Notes
Asset Asset irby Base for all assets (TPH mapping)
AssetHistory AssetHistory irby Audit log for asset changes
AssetModel AssetModel irby Models/manufacturers of assets
AssetModelDetail AssetModelDetail dbo Detailed options per model
Employee Employee irby Field staff
FieldOffice FieldOffice irby Physical offices
Job Job irby Project/job master data
GeneralLedger GeneralLedger irby Accounting GL codes
GLTypeDetail GLTypeDetail dbo Sub‐codes under GL
DocumentImage DocumentImage irby Stores scanned documents
DocumentType DocumentType irby Classification of documents
DocumentAttribute DocumentAttribute irby Metadata attributes for docs
BillingInvoice BillingInvoice irby Invoices
Ticket Ticket irby Support tickets
Update Update irby Ticket update history
And many more – see code for ODS staging tables, CovidTestData, IPMMigration, TempDocumentData, RequestOption, IrbyForms, Issue.

4. Schema Details: Selected Entities

4.1 Asset (Base Class)

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<DateTimeOffset>("PurchaseDate")
    .HasColumnType("datetimeoffset");
  b.Property<string>("Status")
    .IsRequired()
    .HasColumnType("nvarchar(max)");
  b.HasKey("Id");
  b.HasIndex("ModelId");
  b.ToTable("Asset", "irby");
  b.HasDiscriminator<string>("Discriminator")
    .HasValue("Asset");
});
  • Discriminator: Implements Table‑Per‑Hierarchy (TPH) for subclasses like Computer, Monitor, MobileDevice, etc.
  • Indexes: Foreign keys on ModelId, OwnerId, FieldOfficeId.

4.2 Computer (Derived)

modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b => {
  b.HasBaseType("IrbyImaging.DomainClasses.Asset");
  b.Property<string>("UnitNumber").HasColumnName("UnitNumber");
  b.Property<int>("OperatingSystemId");
  b.HasIndex("OperatingSystemId");
  b.ToTable("Asset", "irby");
  b.HasDiscriminator().HasValue("Computer");
});
  • Inherits all columns from Asset plus OS‐specific fields.

4.3 Employee & Job

// Employee
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => {
  b.Property<Guid>("Id").ValueGeneratedOnAdd();
  b.Property<string>("JdeNumber")
    .HasColumnType("nvarchar(450)")
    .IsUnicode();
  b.HasIndex("JdeNumber").IsUnique().HasFilter("[JdeNumber] IS NOT NULL");
  b.HasIndex("CurrentJobId");
  b.ToTable("Employee", "irby");
});

// Job
modelBuilder.Entity("IrbyImaging.DomainClasses.Job", b => {
  b.Property<Guid>("Id").ValueGeneratedOnAdd();
  b.Property<string>("JdeNumber")
    .HasColumnType("nvarchar(450)");
  b.HasIndex("JdeNumber").IsUnique().HasFilter("[JdeNumber] IS NOT NULL");
  b.ToTable("Job", "irby");
});
  • One‑to‑many: Job → Employees
  • Unique business logic constraints on JdeNumber.

5. Relationships & UML Diagram

Main Relationships

  • Asset ↔ AssetHistory: one‐to‐many (an asset can have many history records).
  • AssetModel ↔ Asset: one‐to‐many.
  • Manufacturer ↔ AssetModel: one‐to‐many.
  • Employee ↔ Asset: one‐to‐many (owner).
  • FieldOffice ↔ Asset: one‐to‐many.
  • Job ↔ Employee: one‐to‐many.
  • Ticket ↔ Update: one‐to‐many.

Mermaid ER Diagram

erDiagram
    AssetModel ||--o{ Asset          : "has models"
    Asset      ||--o{ AssetHistory   : "audit log"
    Manufacturer ||--o{ AssetModel   : "makes"
    Employee   ||--o{ Asset          : "owns"
    FieldOffice||--o{ Asset          : "houses"
    Job        ||--o{ Employee       : "staffs"
    Ticket     ||--o{ Update         : "updates"

6. Dependencies & Technologies

  • .NET 5.0
  • C# 9.0
  • Entity Framework Core 5.0.12
  • Microsoft SQL Server (uses SqlServerValueGenerationStrategy.IdentityColumn)
  • Namespaces:
    • Microsoft.EntityFrameworkCore
    • Microsoft.EntityFrameworkCore.Metadata
    • Microsoft.EntityFrameworkCore.Migrations

7. Applying This Migration

  1. Add Migration (already done):
    dotnet ef migrations add TablesForLegalImaging
    
  2. Update Database:
    dotnet ef database update
    
  3. Verify by inspecting the irby schema in your SQL Server instance.

8. Sample Code Snippets

8.1 Registering the DbContext

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<IrbyContext>(options =>
            options.UseSqlServer(
               Configuration.GetConnectionString("DefaultConnection"),
               sqlOptions => sqlOptions.MigrationsAssembly("IrbyImaging.DbContext")));
    }
}

8.2 Querying an Asset with History

using var context = new IrbyContext();
var assetWithHistory = context.Assets
    .Include(a => a.History)    // navigation from Asset to AssetHistory
    .FirstOrDefault(a => a.Id == someGuid);

9. Conclusion

This EF Core designer migration snapshot captures the state of your domain model at 20220607180629. It is critical for:

  • Generating accurate SQL migrations.
  • Tracking model changes over time.
  • Ensuring consistent schema updates across environments.

🔍 Tip: Always review auto‑generated migrations and snapshots before applying to production databases.