π Migration Documentation: 20240523153517_AddAccountingDocumentType.Designer.cs
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Model Changes
- BuildTargetModel Method Breakdown
- Usage & Examples
- Mermaid UML Diagram
- Conclusion
Overview & Purpose
π Migration Name: AddAccountingDocumentType
π
Timestamp: 20240523153517
π File: AddAccountingDocumentType.Designer.cs
This auto-generated EF Core Designer file captures the state of the database model after applying the AddAccountingDocumentType migration. Its primary purpose is to:
- Define the target model structure (via
BuildTargetModel) which EF Core uses to compute future migrations. - Document the addition of the new
AccountingDocumentTypecolumn on theDocumentImagetable.
Tip: Designer files should not be manually editedβthey are regenerated on each migration scaffold.
Dependencies & Technologies
| Technology / Package | Version | Role |
|---|---|---|
| Microsoft.EntityFrameworkCore | v7.0.7 | Core ORM framework |
| Microsoft.EntityFrameworkCore.SqlServer | v7.0.7 | SQL Server provider |
| Microsoft.EntityFrameworkCore.Design | v7.0.7 | Design-time tooling (migrations, scaffolding) |
| .NET 7 | β | Target framework |
Key Functional Areas
-
Model Snapshot
Captures allDbSet<TEntity>configurations after migration. -
Schema Annotations
HasAnnotation("ProductVersion", "7.0.7")UseIdentityColumnsfor SQL Server identity properties.
-
Entity Mappings
Configures tables, columns, primary keys, indexes, relationships, discriminators (TPH inheritance). -
New Column
Introduction ofAccountingDocumentTypeto theDocumentImageentity.
Data Model Changes
DocumentImage Entity
This migration adds a new property:
| Column Name | CLR Type | SQL Type | Nullable | Comments |
|---|---|---|---|---|
| AccountingDocumentType | Guid |
uniqueidentifier |
No | πΌ Tracks the accounting doc type ID |
Before this migration, the DocumentImage table already had other document-type GUIDs:
ITDocumentTypeHRDocumentTypeSafetyDocumentTypeLegalDocumentType
Now it also stores an AccountingDocumentType, enabling specialized indexing and filtering.
BuildTargetModel Method Breakdown
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// β¦ (ALL entities mapping) β¦
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
b.Property<Guid>("DocumentImageId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("AccountingDocumentType") // β NEW PROPERTY
.HasColumnType("uniqueidentifier");
b.Property<Guid>("HRDocumentType")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("ITDocumentType")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("LegalDocumentType")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("SafetyDocumentType")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsAccounting")
.HasColumnType("bit");
// β¦ other existing columns β¦
b.HasKey("DocumentImageId")
.HasName("PrimaryKey_DocumentImageId");
b.ToTable("DocumentImage", "irby");
});
// β¦ (relationships, other entity configurations) β¦
}
Property<Guid>("AccountingDocumentType")
Creates a non-nullableuniqueidentifiercolumn namedAccountingDocumentType.- Table Schema:
irby.DocumentImage
Usage & Examples
Applying the Migration
-
Scaffold Migration
dotnet ef migrations add AddAccountingDocumentType -
Update Database
dotnet ef database updateThis will execute the SQL to add the new column.
Querying with the New Property
using (var context = new IrbyContext())
{
// Create new DocumentImage with accounting type
var accountingTypeId = Guid.Parse("AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE");
var docImage = new DocumentImage
{
DocumentImageId = Guid.NewGuid(),
AccountingDocumentType = accountingTypeId,
DocumentUploadedDate = DateTime.UtcNow,
// β¦ set other required props β¦
};
context.DocumentImages.Add(docImage);
context.SaveChanges();
// Query by accounting document type
var accountingDocs = context.DocumentImages
.Where(d => d.AccountingDocumentType == accountingTypeId)
.ToList();
Console.WriteLine($"Found {accountingDocs.Count} accounting documents.");
}
Mermaid UML Diagram
classDiagram
class DocumentImage {
<<Entity>>
+Guid DocumentImageId
+Guid HRDocumentType
+Guid ITDocumentType
+Guid LegalDocumentType
+Guid SafetyDocumentType
+Guid AccountingDocumentType <-- New
+bool IsAccounting
+string FileName
+DateTime DocumentUploadedDate
+byte[] ImageContents
// β¦ other properties β¦
}
DocumentImage : Table = irby.DocumentImage
Conclusion
π― What We Achieved
- Added a new GUID column (
AccountingDocumentType) to facilitate accounting-focused document categorization. - Captured the complete target model snapshot post-migration, ensuring accurate future diffs.
π§ Next Steps
- Update any UI forms or API endpoints that should allow setting or filtering by
AccountingDocumentType. - Write or update unit/integration tests to cover the new property.
- Ensure indexes are created (via subsequent migrations) if you anticipate high-query loads on
AccountingDocumentType.
Happy Coding! π