π Documentation: 20220209180647_AddDeletedColumn.Designer.cs
Assembly:
IrbyImaging.DbContext
Author: kvamshi
Created: 02-09-2022
Last Modified: 02-15-2022
ποΈ Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models (Entities) & Schema Changes
- Mermaid UML Class Diagram
- Code Snippets & Examples
- Usage & Application in EF Core
- 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 = 128ProductVersion = "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.,
DiscriminatoronAssettable)
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
- Apply Migration
dotnet ef database update 20220209180647_AddDeletedColumn - Code-First Model
Ensure yourDocumentImageclass has:public class DocumentImage { public Guid DocumentImageId { get; set; } public bool IsDeleted { get; set; } // Soft-delete // ... other properties ... } - 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
IsDeletedsoft-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!