πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Model Definitions
  5. Soft‐Deletion Enhancement
  6. Migration Workflow & Usage
  7. Textual UML Diagram
  8. Conclusion

πŸ“ Overview & Purpose

This file, 20230620165643_AddIsDeletedTempDocumentImage.Designer.cs, is auto‑generated by Entity Framework Core (EF Core) as part of the β€œAddIsDeletedTempDocumentImage” migration. Its sole responsibility is to provide a snapshot of the target data model after this migration has been applied.

  • It contains the BuildTargetModel(ModelBuilder modelBuilder) method, which recreates the entire EF Core model (tables, columns, relationships, indexes, discriminator mapping, etc.) as it should exist after running this migration.
  • Do not modify this file by handβ€”EF Core regenerates it when you add or update migrations.

βš™οΈ Dependencies & Technologies

Technology Version / Notes
Microsoft.EntityFrameworkCore Core 7.0.7 (ProductVersion)
Microsoft.EntityFrameworkCore.SqlServer EF Core SQL Server provider
.NET 7.0.x (implied by EF Core version)
SQL Server Using Identity Columns for PK generation
C# .NET 7 single‑file migration scaffolding

πŸš€ Key Functional Areas

  1. Model Snapshot
    Rebuilds every entity, property, index, key, table name, schema, discriminator, etc.

  2. Entity Configuration
    Defines each DomainClasses.* entity mapping:

    • Columns (.Property<T>("Name"))
    • Keys (.HasKey(...))
    • Indexes (.HasIndex(...))
    • Relationships / Navigation properties
    • Table & schema (.ToTable("Name", "irby"))
  3. Inheritance (TPH)
    Implements Table‐Per‐Hierarchy for Asset and its derived classes (Computer, DeskPhone, etc.) with .HasDiscriminator().

  4. Soft‐Deletion Flag
    Adds the IsDeleted column to TempDocumentData (and similarly handled on DocumentImage) enabling logical (soft) deletion.


πŸ’Ύ Data Model Definitions

Below are snippets for two representative entities.

Tip: The full file declares dozens of tables; you can scroll through to inspect each one.

1. TempDocumentData (Soft‐Deletion Added)

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

    // … other existing properties …
    b.Property<bool>("IsDeleted")
     .HasColumnType("bit");      // << NEW: soft‐delete flag

    b.Property<bool>("IsIndexed")
     .HasColumnType("bit");
    b.Property<int>("Page")
     .HasColumnType("int");
    b.Property<Guid>("ReferenceId")
     .HasColumnType("uniqueidentifier");
    b.HasKey("TempDocumentDataId");
    b.ToTable("TempDocumentData", "irby");
});

2. DocumentImage

modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b => {
    b.Property<Guid>("DocumentImageId")
     .HasColumnType("uniqueidentifier");
    // … image metadata columns …
    b.Property<bool>("IsDeleted")
     .HasColumnType("bit");      // indicates logical deletion

    b.ToTable("DocumentImage", "irby");
});

πŸ”’ Soft‐Deletion Enhancement

With soft‐deletion you mark records as deleted instead of physically removing them from the table.

  • Why?

    • Auditability: You can track delete timestamps.
    • Recovery: Accidentally deleted data can be restored.
    • Referential Integrity: Avoid breaking FK constraints by removing rows.
  • How it's implemented in this migration:

    1. Adds the IsDeleted boolean column to the target tables (TempDocumentData, DocumentImage, etc.).
    2. You can then update your repository or service layer to exclude rows where IsDeleted = true.
    3. Optionally, add a date/stamp column in a subsequent migration for better tracking.

πŸ”§ Migration Workflow & Usage

1. Adding this Migration

# With EF Core CLI
dotnet ef migrations add AddIsDeletedTempDocumentImage

# Or via Package Manager Console (Visual Studio)
Add-Migration AddIsDeletedTempDocumentImage

2. Applying to Database

# EF Core CLI
dotnet ef database update

# PMC
Update-Database

Note: EF Core will read the Up() and Down() methods in the companion .cs migration file (not this designer file) to actually ALTER tables, adding the new columns.


πŸ“Š Textual UML Diagram

Below is a textual representation of some key relationships:

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      
                    β”‚   AssetModel   │───────┐
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
                            β–²               β”‚1
                            β”‚*              β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    Asset       │───────┼────│Operator   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜TPH    β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β–²  β–²     β–²   β–²         β”‚
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚  β”‚     β”‚   β”‚         β”‚
      β”‚Computer β”‚     β”‚  β”‚     β”‚   β”‚         β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”Œβ”€β”€β”˜  β”‚     β”‚   β”‚         β”‚
                  β”‚      β”‚     β”‚   β”‚         β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”β”Œβ”€β”€β”€β”€β”€β”€β”€β”      β”‚
              β”‚Dock  β”‚ β”‚Phoneβ”‚β”‚Monitorβ”‚      β”‚
              β””β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
                                            *β”‚
                                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                         β”‚ TempDocumentDataβ”‚
                                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                  β–²
                                                  β”‚
                                                  β”‚
                                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                       β”‚   DocumentImage     β”‚
                                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • 1: One AssetModel has many Asset
  • TPH: Table‐Per‐Hierarchy for all asset subtypes.
  • TempDocumentData and DocumentImage are independent entities.

βœ… Conclusion

This auto‐generated designer file is a critical part of EF Core’s migration system. It:

  • Provides a model snapshot after the migration
  • Ensures EF Core can calculate future diffs correctly
  • Includes the newly introduced IsDeleted flag for soft-deletion

Never edit it manuallyβ€”regenerate migrations if your model changes. Instead, focus on:

  1. Updating your DomainClasses (add public bool IsDeleted { get; set; }).
  2. Running dotnet ef migrations add …
  3. Applying via dotnet ef database update.

With this soft‐delete mechanism in place, you can now implement logical deletes across your imaging database tables and preserve historical data integrity. πŸš€