π 20220613155005_NewColumnDocumentImageTable.Designer.cs Documentation
π Table of Contents
- Overview & Purpose
- Migration Context
- Dependencies & Technologies
- Key Functional Areas
- Data Model Definitions
5.1. Asset Hierarchy
5.2. Document-Related Entities
5.3. Other Core Entities - Entity Relationships & Inheritance
- Spotlight: DocumentImage Entity Changes
- BuildTargetModel Method Walkthrough
- UML Class Diagram (Excerpt)
- How EF Core Uses This File
- Usage Examples
- Conclusion
1. Overview & Purpose
This auto-generated Designer file is part of the Entity Framework Core Migrations in the IrbyImaging.DbContext assembly. It captures the complete snapshot of the EF Core model after the migration named:
[Migration("20220613155005_NewColumnDocumentImageTable")]
public partial class NewColumnDocumentImageTable : Migration
{
// ...
}
Purpose
- Records table and column mappings.
- Annotates primary/foreign keys, indexes, discriminator configurations for inheritance.
- Ensures EF Core can compute diffs between model snapshots when adding/removing migrations.
2. Migration Context
π Migration Name: 20220613155005_NewColumnDocumentImageTable
π What It Does:
- Reflects new column(s) added to the
DocumentImagetable in theirbyschema. - Updates the EF model snapshot to include these new properties so downstream migrations know the current state.
3. Dependencies & Technologies
| Dependency | Purpose |
|---|---|
| Microsoft.EntityFrameworkCore (v5.0.12) | Core ORM framework |
| Microsoft.EntityFrameworkCore.Relational | Relational database features (indexes, schema) |
| Microsoft.EntityFrameworkCore.SqlServer | SQL Server provider |
| Microsoft.EntityFrameworkCore.Migrations | Migrations API |
IrbyImaging.DbContext assembly |
Contains the IrbyContext and domain classes |
4. Key Functional Areas
- Model Snapshot
Defines how domain classes map to tables & columns. - Annotations & Conventions
.HasAnnotation("ProductVersion", "5.0.12"),.HasAnnotation("SqlServer:ValueGenerationStrategy", IdentityColumn) - Entity Configurations
Entities likeAsset,DocumentImage,Employee, etc. - Inheritance Mapping
Table-per-hierarchy via.HasDiscriminator()forAssetand its subclasses.
5. Data Model Definitions
5.1. Asset Hierarchy
| Entity | Table | Discriminator |
|---|---|---|
| Asset (base) | irby.Asset |
"Asset" |
| ββ Computer | irby.Asset |
"Computer" |
| ββ DeskPhone | irby.Asset |
"DeskPhone" |
| ββ Dock | irby.Asset |
"Dock" |
| ββ MobileDevice | irby.Asset |
"MobileDevice" |
| ββ Monitor | irby.Asset |
"Monitor" |
| ββ NetworkEquipment | irby.Asset |
"NetworkEquipment" |
| ββ OfficePrinter | irby.Asset |
"OfficePrinter" |
| ββ Printer | irby.Asset |
"Printer" |
| ββ SafetyEquipment | irby.Asset |
"SafetyEquipment" |
5.2. Document-Related Entities
| Entity | Table | Description |
|---|---|---|
| DocumentAttribute | irby.DocumentAttribute |
Attributes (metadata) for docs |
| DocumentImage | irby.DocumentImage |
Holds image contents & OCR results |
| DocumentType | irby.DocumentType |
Type definitions |
| TempDocumentData | irby.TempDocumentData |
Staging area for document data |
| IPMMigration | irby.IPMMigration |
Legacy migration staging |
| IrbyForms | irby.IrbyForms |
Special form images |
5.3. Other Core Entities
- AssetModel, AssetModelDetail, Manufacturer
- Employee, Job, FieldOffice
- GeneralLedger, GLTypeDetail, BillingInvoice
- Ticket & Update (ticket history)
- ODS_Employee_Staging, ODS_Jobs_Staging (ETL staging)
- CovidTestData, RequestOption, Issue
6. Entity Relationships & Inheritance
-
Foreign Keys & Navigation
- Asset β AssetModel (
ModelId) - Asset β FieldOffice (
FieldOfficeId) - Asset β Employee (
OwnerId) - Computer/SafetyEquipment β OperatingSystem
- Employee β Job
- FieldOffice β Employee (Manager/ProjectManager/Superintendent)
- Ticket β Update
- Asset β AssetModel (
-
Inheritance (TPH)
All subtypes ofAssetshare theirby.Assettable; distinguished by theDiscriminatorcolumn.
7. Spotlight: DocumentImage Entity Changes
This migrationβs focus is on DocumentImage.
Hereβs a before/after comparison (conceptual):
| Column | Type | Notes |
|---|---|---|
| DocumentImageId | uniqueidentifier |
Primary key |
| FileName | nvarchar(max) |
|
| ImageContents | varbinary(max) |
|
| DocumentNotes | nvarchar(max) |
New notes field |
| DocumentIndexes | nvarchar(max) |
New indexing metadata (JSON?) |
| ... | ... | Other existing columns |
Why?
- Capture freeβform notes for a document.
- Store structured indexes/tags for search & categorization.
8. BuildTargetModel Method Walkthrough
[DbContext(typeof(IrbyContext))]
[Migration("20220613155005_NewColumnDocumentImageTable")]
partial class NewColumnDocumentImageTable : Migration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// 1οΈβ£ Global annotations
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.12")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// 2οΈβ£ Entity configuration for DocumentImage
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
b.Property<Guid>("DocumentImageId").HasColumnType("uniqueidentifier");
b.Property<string>("FileName").HasColumnType("nvarchar(max)");
b.Property<byte[]>("ImageContents").HasColumnType("varbinary(max)");
b.Property<string>("DocumentNotes").HasColumnType("nvarchar(max)"); // π new column
b.Property<string>("DocumentIndexes").HasColumnType("nvarchar(max)"); // π new column
// ... other properties ...
b.HasKey("DocumentImageId").HasName("PrimaryKey_DocumentImageId");
b.ToTable("DocumentImage", "irby");
});
// 3οΈβ£ More entities...
}
}
Highlights
- Each
modelBuilder.Entity(...)block maps a CLR type to a table. .Property<>()defines column name, type, nullability..HasKey(),.HasIndex(),.HasOne()/WithMany()set up PKs, indexes, FKs.
9. UML Class Diagram (Excerpt)
@startuml
class DocumentImage {
+Guid DocumentImageId
+string FileName
+byte[] ImageContents
+string DocumentNotes
+string DocumentIndexes
+bool IsDeleted
+DateTime DocumentUploadedDate
...
}
DocumentImage --> DocumentType
DocumentImage --> Employee : DocumentUploadedBy
@enduml
Export with PlantUML to visualize entity properties and relationships.
10. How EF Core Uses This File
- Scaffold: When you add a migration (
dotnet ef migrations add ...), EF generates the.cs&.Designer.cs. - Snapshot: The Designer file is the model snapshot β EF compares it to the live model to generate future diffs.
- Apply: On
dotnet ef database update, EF ensures DB schema aligns with the latest migration scripts (not the Designer).
11. Usage Examples
Add a Migration
dotnet ef migrations add NewColumnDocumentImageTable \
--project IrbyImaging.DbContext \
--startup-project IrbyImaging.WebApi
Update Database
dotnet ef database update 20220613155005_NewColumnDocumentImageTable
Accessing the New Columns in Code
using var db = new IrbyContext();
var doc = await db.DocumentImages.FindAsync(someId);
doc.DocumentNotes = "Scanned on site by John Doe.";
doc.DocumentIndexes = "[\"invoice\",\"contract\"]";
await db.SaveChangesAsync();
12. Conclusion
This Designer snapshot is a vital piece of the EF Core Migrations machinery. It:
- Guarantees consistency between your C# domain model and database schema.
- Documents every entity, property, index, and relationship.
- Ensures that the
DocumentImagetable now contains the newly introduced fieldsDocumentNotesandDocumentIndexes.
By understanding its structure, you can confidently extend your data model, add migrations, and maintain schema evolution in a controlled, repeatable manner. π
Happy coding! π οΈ