📦 IrbyImaging.DbContext Migrations Documentation
File: 20220303202752_AddIsDeleted.Designer.cs
Table of Contents 🗂
- Overview & Purpose 🎯
- Key Functional Areas 🧩
- Dependencies & Technologies 🖥️
- View Models & Data Models 💾
- Helper Methods / Utilities 🔧
- Error Handling & Return Types ⚠️
- API Endpoints Overview 📋
- Third‑party Integrations 🔗
- Sample Code Blocks 📝
- Usage Examples 🚀
- UML Diagram 📈
- Conclusion 🎉
1. Overview & Purpose 🎯
This file is an auto‑generated designer for the Entity Framework Core migration named AddIsDeleted (timestamp 20220303202752) in the IrbyImaging.DbContext.Migrations namespace. It ties to the IrbyContext DbContext and captures the entire model snapshot after applying the migration.
🔍 Primary Role:
- Define all entities, properties, keys, indexes, relationships, and value‑generation strategies.
- Provide a baseline for EF Core to compute future schema differences.
⚠️ Note:
This designer file does not containUp()orDown()methods. It only implementsBuildTargetModel().
2. Key Functional Areas 🧩
| Functional Area | Description |
|---|---|
| BuildTargetModel | Reconstructs the EF Core model graph (entities + relationships). |
| Entity Definitions | Schemas for Asset, BillingInvoice, DocumentImage, AssetHistory, etc. |
| TPH Inheritance | Table‑Per‑Hierarchy mapping for Asset subtypes (Computer, MobileDevice, etc.). |
| Value Generation | Configures SQL Server Identity columns and default value conversions. |
| Soft‑Delete Flag | Models the new IsDeleted boolean on BillingInvoice & DocumentImage. |
3. Dependencies & Technologies 🖥️
- .NET 5.0
- Entity Framework Core 5.0.12
- Packages:
Microsoft.EntityFrameworkCoreMicrosoft.EntityFrameworkCore.SqlServerMicrosoft.EntityFrameworkCore.Migrations
- Packages:
- C# 9.0 (Partial classes, nullable references, etc.)
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
4. View Models & Data Models 💾
View Models
❌ None in this file. Focus is solely on database schema.
Data Models
The designer snapshot includes 30+ entities. Below is a concise table of the core domain classes:
| Entity | Primary Key | Notable Columns | Schema | Table |
|---|---|---|---|---|
| Asset | Guid Id |
Category, Discriminator, ModelId, OwnerId, PurchaseDate | irby |
Asset (TPH) |
| AssetHistory | Guid Id |
AssetId, Action, ModifiedBy, Timestamp | irby |
AssetHistory |
| AssetModel | int Id |
Name, Category, MakeId | irby |
AssetModel |
| AssetModelDetail | int Id |
AssetModelId, Name, Category | dbo |
AssetModelDetail |
| BillingInvoice | Guid Id |
Charge, FileName, IsDeleted (new soft‑delete flag) | irby |
BillingInvoice |
| DocumentImage | Guid DocumentImageId |
FileName, ImageContents, IsDeleted (new soft‑delete flag) | irby |
DocumentImage |
| Employee | Guid Id |
FirstName, LastName, JdeNumber | irby |
Employee |
| FieldOffice | Guid Id |
Name, JdeNumber, ManagerId | irby |
FieldOffice |
| Job | Guid Id |
Name, JdeNumber | irby |
Job |
| GeneralLedger | Guid Id |
Code, Description | irby |
GeneralLedger |
| GLTypeDetail | Guid Id |
Code, Description, GeneralLedgerId | dbo |
GLTypeDetail |
| Manufacturer | int Id |
Name, WarrantyMonths | irby |
AssetManufacturer |
| OperatingSystem | int Id |
Name | irby |
OperatingSystem |
| … plus staging (ODS) and other audit tables._ |
5. Helper Methods / Utilities 🔧
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);
// Example: BillingInvoice with new IsDeleted
modelBuilder.Entity("IrbyImaging.DomainClasses.BillingInvoice", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsDeleted") // <-- New soft‑delete flag
.HasColumnType("bit")
.HasDefaultValue(false);
// …other column mappings…
});
#pragma warning restore 612, 618
}
BuildTargetModel: Configures the EF Core model based on the current domain classes.#pragma warning: Suppresses EF Core–generated obsolete warnings.
6. Error Handling & Return Types ⚠️
- Return Type:
void(configures theModelBuilderinstance). - Error Handling:
- No custom
try/catch. - Any exceptions during model building bubble up through the EF Core runtime.
- No custom
7. API Endpoints Overview 📋
🔍 N/A – This migration file does not define or interact with Web/API endpoints.
8. Third‑party Integrations 🔗
| Library / Framework | Purpose |
|---|---|
| Entity Framework Core | Object‑Relational Mapping (ORM) |
| SQL Server Provider | SQL Server database connectivity |
| ValueConversion APIs | Column value converters (e.g., enums) |
9. Sample Code Blocks 📝
Migration Up/Down (in AddIsDeleted.cs)
public partial class AddIsDeleted : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsDeleted",
schema: "irby",
table: "BillingInvoice",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "IsDeleted",
schema: "irby",
table: "DocumentImage",
type: "bit",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn("IsDeleted", "irby.BillingInvoice");
migrationBuilder.DropColumn("IsDeleted", "irby.DocumentImage");
}
}
Querying Soft‑Deleted Records
var deletedInvoices = context.BillingInvoices
.Where(inv => inv.IsDeleted)
.ToList();
10. Usage Examples 🚀
- Add & Scaffold Migration
dotnet ef migrations add AddIsDeleted - Apply to Database
dotnet ef database update - Perform Soft‑Delete
var invoice = context.BillingInvoices.Find(invoiceId); invoice.IsDeleted = true; context.SaveChanges();
11. UML Diagram 📈
@startuml
namespace irby {
class Asset {
+Id : Guid
+Category : string
+Discriminator : string
+ModelId : int
+OwnerId : Guid?
+PurchaseDate : DateTimeOffset
}
class BillingInvoice {
+Id : Guid
+Charge : decimal
+IsDeleted : bool
+FileName : string
}
class DocumentImage {
+DocumentImageId : Guid
+IsDeleted : bool
+ImageContents : byte[]
}
Asset --> AssetHistory : "1..*"
AssetModel --> Asset : "1..*"
Asset <|-- Computer
Asset <|-- MobileDevice
BillingInvoice .. IsDeletedFlag
DocumentImage .. IsDeletedFlag
}
@enduml
Use any PlantUML tool to render the above diagram.
12. Conclusion 🎉
The 20220303202752_AddIsDeleted.Designer.cs file captures a comprehensive model snapshot after introducing the soft‑delete capability via the IsDeleted flag on BillingInvoice and DocumentImage tables. It ensures EF Core can accurately diff future model changes, maintain schema consistency, and enable soft‑delete patterns throughout the application’s data access layer.
Happy coding & soft‑deleting! 🚀