πŸ“‘ Documentation: 20220209180647_AddDeletedColumn.Designer.cs

Assembly: IrbyImaging.DbContext
Author: kvamshi
Created: 02-09-2022
Last Modified: 02-15-2022


πŸ—‚οΈ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Models (Entities) & Schema Changes
  5. Mermaid UML Class Diagram
  6. Code Snippets & Examples
  7. Usage & Application in EF Core
  8. Conclusion

πŸ“ Overview & Purpose

This file is an Entity Framework Core migration designer snapshot for the migration named 20220209180647_AddDeletedColumn. It captures the target model after applying changesβ€”most notably adding a soft-delete flag (IsDeleted) to the DocumentImage entity.

  • πŸ”„ EF Core uses this snapshot to compute diffs between your code-first model and the database schema.
  • πŸ› οΈ This file is auto-generated; you typically do not edit it by hand.
  • πŸš€ It ensures that future migrations and model scaffolding are aware of this new column and other schema details.

πŸ“¦ Dependencies & Technologies

Technology Version / Role
Entity Framework Core 5.0.12 (SQL Server provider)
.NET .NET 5.0 (implied by EF Core 5.x)
C# Partial classes, annotations, LINQ-friendly model configuration

Key namespaces:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

πŸ”‘ Key Functional Areas

1. Migration Metadata

[DbContext(typeof(IrbyContext))]
[Migration("20220209180647_AddDeletedColumn")]
partial class AddDeletedColumn : Migration
{ ... }
  • DbContext Attribute: Binds this migration to IrbyContext.
  • Migration Attribute: Uniquely identifies this migration by timestamp & name.

2. BuildTargetModel Method

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

    // Entity configurations follow...
    #pragma warning restore 612, 618
}
  • Purpose: Re-creates the EF Core model as it should exist after the migration.
  • Annotations:
    • MaxIdentifierLength = 128
    • ProductVersion = "5.0.12"
    • Identity columns strategy for SQL Server.

3. Entity Configurations

Inside BuildTargetModel, each domain class is mapped:

  • Table Schema (e.g., ToTable("Asset", "irby"))
  • Columns: name, CLR type, SQL type, nullability
  • Keys & Indexes
  • Discriminator columns for inheritance (e.g., Discriminator on Asset table)

Example snippet for the Asset base entity:

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

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

    // ... more properties ...

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

4. Relationships & Navigation

After defining all entities, navigation properties and foreign keys 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.Navigation("FieldOffice");
    b.Navigation("Model");
});
  • HasOne / WithMany: Sets up one-to-many relationships.
  • OnDelete(DeleteBehavior.Cascade): Cascade delete semantics.
  • Navigation(...): Registers navigation for lazy/eager loading.

πŸ—ƒοΈ Data Models (Entities) & Schema Changes

This snapshot covers 23+ entities including:

  • Asset-related: Asset, Computer, MobileDevice, DeskPhone, etc.
  • Document handling: DocumentImage, TempDocumentData, IPMMigration
  • Employee & Office: Employee, FieldOffice, Job, ODSEmployee, ODSJob
  • Asset catalog: AssetModel, AssetModelDetail, Manufacturer, OperatingSystem
  • Audit/history: AssetHistory, CovidTestData

Highlighted Change: IsDeleted Column πŸ”

Table (Schema: irby) Column Type Nullable Description
DocumentImage IsDeleted bit false Soft-delete flag (new)
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
    b.Property<bool>("IsDeleted")
     .HasColumnType("bit");
    // ... other properties ...
    b.HasKey("DocumentImageId");
    b.ToTable("DocumentImage", "irby");
});

🎯 Purpose: Enables soft-deleting of images without physically removing rows.


πŸ“Š Mermaid UML Class Diagram

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

    AssetModel "1" o-- "*" AssetModelDetail
    Manufacturer "1" o-- "*" AssetModel
    Job "1" o-- "*" Employee
    FieldOffice "1" o-- "*" Asset
    Employee "1" o-- "*" Asset

    DocumentImage --|> TempDocumentData : similar structure
    TempDocumentData -- IPMMigration : tracks migrations

πŸ’» Code Snippets & Examples

Snippet: BuildTargetModel Structure

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    // Basic model annotations
    modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128)
                .HasAnnotation("ProductVersion", "5.0.12")
                .HasAnnotation("SqlServer:ValueGenerationStrategy",
                               SqlServerValueGenerationStrategy.IdentityColumn);

    // Entity: DocumentImage with new IsDeleted flag
    modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
    {
        b.Property<Guid>("DocumentImageId").HasColumnType("uniqueidentifier");
        b.Property<bool>("IsDeleted").HasColumnType("bit");
        // ... more columns ...
        b.HasKey("DocumentImageId");
        b.ToTable("DocumentImage", "irby");
    });

    // ... other entities ...
}

πŸ” Usage & Application in EF Core

  1. Apply Migration
    dotnet ef database update 20220209180647_AddDeletedColumn
    
  2. Code-First Model
    Ensure your DocumentImage class has:
    public class DocumentImage
    {
        public Guid DocumentImageId { get; set; }
        public bool IsDeleted { get; set; }   // Soft-delete
        // ... other properties ...
    }
    
  3. Querying Soft-Deleted Records
    // Get only active images
    var images = context.DocumentImages
                        .Where(d => !d.IsDeleted)
                        .ToList();
    

🎯 Conclusion

This designer snapshot is the blueprint of the EF Core model after the AddDeletedColumn migration. It centrally documents:

  • βœ… All entity-to-table mappings
  • βœ… The newly added IsDeleted soft-delete flag
  • βœ… Relationships, keys, indexes, and inheritance discriminators

Understanding this file helps you trace schema changes, debug migrations, and ensure your code-first classes align with the SQL Server database schema.


Generated by EF Core – do not modify manually!