📑 Migration Documentation: 20230706142626_NewIsLegalDocumentColumnDocumentCategory.Designer.cs
Location:
IrbyImaging.DbContext/Migrations/20230706142626_NewIsLegalDocumentColumnDocumentCategory.Designer.cs
Purpose: Snapshot of the EF Core model after adding a new boolean columnIsLegalDocumentto theDocumentCategoryentity.
🚀 Table of Contents
- Overview & Purpose
- EF Core Migrations Primer
- Key Functional Areas
- Dependencies & Technologies
- Data Models Snapshot
- How It Works
- Usage & Code Snippets
- UML Diagram (Partial)
- Conclusion & Next Steps
🔍 1. Overview & Purpose
This .Designer.cs file is an auto‑generated snapshot of the Entity Framework Core model at the time of applying the migration
NewIsLegalDocumentColumnDocumentCategory. Its primary responsibilities are:
- Reconstructing the
ModelBuilderconfiguration to match the current domain model. - Ensuring EF Core knows how to build the target schema (tables, columns, keys, relationships).
- Capturing the addition of
IsLegalDocumenttoDocumentCategory.
💡 Note: You should not manually edit this file. Use migrations to evolve your model instead.
🛠️ 2. EF Core Migrations Primer
Entity Framework Core Migrations provide:
- Schema Evolution: Add/remove columns, tables, constraints.
- Version Control: Each migration is timestamped (e.g.,
20230706142626_...). - Snapshot Comparison: EF compares the previous snapshot to your current domain model to scaffold changes.
There are three key files per migration:
| File | Role |
|---|---|
*.cs (Migration class) |
Contains Up()/Down() logic |
*.Designer.cs (This file) |
Model snapshot for comparisons |
*.resx |
Localization resources (rarely used) |
🔑 3. Key Functional Areas
- Model Annotations
- Sets global annotations (e.g., SQL Server version, identity columns).
- Entity Configurations
- Defines entities, properties, keys, indexes, relationships.
- Discriminator Mapping
- Configures Table‑Per‑Hierarchy (TPH) for
Assetsubtypes.
- Configures Table‑Per‑Hierarchy (TPH) for
- New Column Capture
- Highlights the newly added boolean property in
DocumentCategory.
- Highlights the newly added boolean property in
📦 4. Dependencies & Technologies
- .NET 7.0
- Entity Framework Core 7.0.7
- SQL Server (via
Microsoft.EntityFrameworkCore.SqlServer) - Domain Classes under
IrbyImaging.DomainClasses
🧩 5. Data Models Snapshot
Below are highlights of the domain entities as captured in the snapshot. We’ve grouped the most relevant ones around document management.
📂 DocumentCategory (with new column)
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentCategory", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("AddedBy")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("AddedDate")
.HasColumnType("datetime2");
b.Property<string>("Description")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsAvailable")
.HasColumnType("bit");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
// 🆕 Newly added property
b.Property<bool>("IsLegalDocument")
.HasColumnType("bit");
b.Property<bool>("IsSafety")
.HasColumnType("bit");
b.Property<string>("ModifiedBy")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("ModifiedDate")
.HasColumnType("datetime2");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("DocumentCategory", "irby");
});
IsLegalDocument:- Type:
bool(bitin SQL Server) - Purpose: Flag a document category as "legal" for downstream filtering/processing.
- Type:
🔦 Snapshot Highlights
| Entity | Notes |
|---|---|
| DocumentAttribute | Also has IsLegalDocument for attribute‑level tagging. |
| DocumentImage | Stores document blobs, OCR data, plus IsLegalDocument and IsSafety flags. |
| TempDocumentData | Staging table for incoming docs, including IsLegalDocument. |
| Toners, Jobs, Assets… | Over 40+ domain classes configured (Assets, Employees, Jobs, Tickets, etc.). |
These configurations ensure referential integrity, indexes on unique fields (e.g., IMEI, JdeNumber), and TPH inheritance for assets.
⚙️ 6. How It Works
-
BuildTargetModel(...)
- Called by EF Core during
dotnet ef database update. - Replays all the
modelBuilderconfiguration to reconstruct the model.
- Called by EF Core during
-
Migration Application
- EF Core compares the previous snapshot to this target snapshot.
- Detects the addition of
DocumentCategory.IsLegalDocument. - Generates SQL in the
Up()method of the migration toALTER TABLE ... ADD IsLegalDocument bit NOT NULL DEFAULT 0.
-
Rolling Back
- The
Down()method would drop the column if rolling back the migration.
- The
📝 7. Usage & Code Snippets
Applying the Migration
# Add migration (already done):
dotnet ef migrations add NewIsLegalDocumentColumnDocumentCategory
# Update database:
dotnet ef database update
Filtering Legal Document Categories
using var context = new IrbyContext();
// Fetch only legal categories
var legalCategories = context.DocumentCategories
.Where(dc => dc.IsLegalDocument)
.OrderBy(dc => dc.Name)
.ToList();
📊 8. UML Diagram (Partial)
@startuml
class DocumentCategory {
+ Guid Id
+ string Name
+ string Description
+ bool IsAvailable
+ bool IsDeleted
+ bool IsSafety
+ bool IsLegalDocument << New >>
+ DateTime AddedDate
+ string AddedBy
+ DateTime ModifiedDate
+ string ModifiedBy
}
DocumentCategory ..> DocumentType : 1..*
DocumentCategory ..> DocumentAttribute : 1..*
@enduml
Use PlantUML to render the above class diagram showing the new
IsLegalDocumentproperty.
✅ 9. Conclusion & Next Steps
- Auto‑generated snapshot ensures EF Core knows the target schema.
IsLegalDocumentenables new business logic (e.g., compliance workflows or legal dashboards).- After applying this migration, you can:
- Update UI/Forms to toggle "Legal Document" status.
- Implement filter/authorization logic based on the new flag.
🎉 Congratulations! Your database is now primed to distinguish legal vs. non‑legal document categories at scale.