π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Model Definitions
- SoftβDeletion Enhancement
- Migration Workflow & Usage
- Textual UML Diagram
- 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
-
Model Snapshot
Rebuilds every entity, property, index, key, table name, schema, discriminator, etc. -
Entity Configuration
Defines eachDomainClasses.*entity mapping:- Columns (
.Property<T>("Name")) - Keys (
.HasKey(...)) - Indexes (
.HasIndex(...)) - Relationships / Navigation properties
- Table & schema (
.ToTable("Name", "irby"))
- Columns (
-
Inheritance (TPH)
Implements TableβPerβHierarchy forAssetand its derived classes (Computer,DeskPhone, etc.) with.HasDiscriminator(). -
SoftβDeletion Flag
Adds theIsDeletedcolumn toTempDocumentData(and similarly handled onDocumentImage) 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:
- Adds the
IsDeletedboolean column to the target tables (TempDocumentData,DocumentImage, etc.). - You can then update your repository or service layer to exclude rows where
IsDeleted = true. - Optionally, add a date/stamp column in a subsequent migration for better tracking.
- Adds the
π§ 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()andDown()methods in the companion.csmigration 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
AssetModelhas manyAsset - 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:
- Updating your DomainClasses (add
public bool IsDeleted { get; set; }). - Running
dotnet ef migrations add β¦ - 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. π