π Table of Contents
- π Overview & Purpose
- π Dependencies & Technologies
- ποΈ Key Functional Areas
- ποΈ Data Models & Schema
- βοΈ Migration Intent β Adding
IndexTag - π Sample Code Snippets
- πΌοΈ UML Class Diagram
- π Usage Examples
- π― Conclusion
π Overview & Purpose
File:
IrbyImaging.DbContext/
βββ Migrations/
βββ 20230619190753_AddIndexTagColumn.Designer.cs
This auto-generated Designer file is part of an Entity Framework Core migration named AddIndexTagColumn. It contains the target model snapshotβi.e. the BuildTargetModel(ModelBuilder) methodβwhich describes the complete database schema after this migration is applied.
Why it exists:
- Enables EF Core to compute diffs when creating future migrations.
- Serves as a blueprint for the
IrbyContextmodel. - Ensures consistency between your C# classes and the SQL database schema.
π Dependencies & Technologies
- .NET & C# (β₯ .NETΒ 7.0, C#Β 11)
- Entity Framework Core 7.0.7
- Microsoft.EntityFrameworkCore.SqlServer
- SQL Server (relational database provider)
ποΈ Key Functional Areas
-
Global Annotations & Identity Setup
.HasAnnotation("ProductVersion", "7.0.7").HasAnnotation("Relational:MaxIdentifierLength", 128)SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder)
-
Entity Configurations
- ~30 domain classes (e.g.,
Asset,Employee,Job) - TPH (TableβPerβHierarchy) for
Assetsubtypes (Computer, DeskPhone, MobileDevice, etc.) - Column types, lengths, required/nullable flags
- ~30 domain classes (e.g.,
-
Indexes & Constraints
- Unique indexes (e.g.,
Employee.JdeNumber) - Filtered indexes for nullable columns
- Foreign key indexes for relationships
- Unique indexes (e.g.,
-
Relationships & Navigation
- Oneβtoβmany & manyβtoβone mappings
- Cascade delete behaviors
- Fluent API navigation registrations
ποΈ Data Models & Schema
Below is a condensed view of some of the primary entities, their tables, keys, and the new IndexTag column:
| Entity Class | Table (Schema) | Primary Key | Notes |
|---|---|---|---|
| TempDocumentData π New | irby.TempDocumentData |
TempDocumentDataId : uniqueidentifier |
+ IndexTag (nvarchar(max)) |
| Asset | irby.Asset |
Id : uniqueidentifier |
TPH with discriminator |
| AssetModel | irby.AssetModel |
Id : int (Identity) |
FK β Manufacturer |
| Employee | irby.Employee |
Id : uniqueidentifier |
Unique index on JdeNumber |
| Job | irby.Job |
Id : uniqueidentifier |
Unique index on JdeNumber |
| FieldOffice | irby.FieldOffice |
Id : uniqueidentifier |
Unique index on JdeNumber |
| β¦ | β¦ | β¦ | β¦ |
Tip: This file configures all domain classes under the
IrbyImaging.DomainClassesnamespace.
βοΈ Migration Intent β Adding IndexTag
The heart of this migration is to introduce a new metadata column, IndexTag, onto the TempDocumentData table. This allows temporary documents to carry a custom tag for indexing or categorization.
What changed?
- Up() adds the column:
migrationBuilder.AddColumn<string>( name: "IndexTag", schema: "irby", table: "TempDocumentData", type: "nvarchar(max)", nullable: true); - Down() removes it:
migrationBuilder.DropColumn( name: "IndexTag", schema: "irby", table: "TempDocumentData");
Snapshot in Designer
modelBuilder.Entity("IrbyImaging.DomainClasses.TempDocumentData", b =>
{
b.Property<Guid>("TempDocumentDataId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// β¦ other properties β¦
b.Property<string>("IndexTag")
.HasColumnType("nvarchar(max)"); // β New
b.ToTable("TempDocumentData", "irby");
});
π Sample Code Snippets
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// 1. Global annotations
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// 2. Identity columns for SQL Server
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// 3. Configure TempDocumentData
modelBuilder.Entity("IrbyImaging.DomainClasses.TempDocumentData", b =>
{
b.Property<Guid>("TempDocumentDataId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// β Newly added column
b.Property<string>("IndexTag")
.HasColumnType("nvarchar(max)");
// β¦ other columns β¦
b.ToTable("TempDocumentData", "irby");
});
// 4. Configure other entitiesβ¦
}
Defining a Unique Index
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
b.HasIndex("JdeNumber")
.IsUnique()
.HasFilter("[JdeNumber] IS NOT NULL");
});
πΌοΈ UML Class Diagram
classDiagram
Asset <|-- Computer
Asset <|-- DeskPhone
Asset <|-- Dock
Asset <|-- MobileDevice
Asset <|-- Monitor
Asset <|-- NetworkEquipment
Asset <|-- OfficePrinter
Asset <|-- Printer
Asset <|-- SafetyEquipment
AssetModelDetail --|> AssetModel
AssetModel --> Manufacturer : Make
Asset --> AssetModel : Model
Asset --> FieldOffice : FieldOffice
Asset --> Employee : Owner
Computer --> OperatingSystem : OperatingSystem
SafetyEquipment --> OperatingSystem : OperatingSystem
π Usage Examples
1. Reading the IndexTag
using var db = new IrbyContext();
var temp = db.TempDocumentData.FirstOrDefault();
Console.WriteLine($"IndexTag: {temp?.IndexTag}");
2. Updating the IndexTag
var doc = db.TempDocumentData.Find(myId);
doc.IndexTag = "Invoice-2023-07";
await db.SaveChangesAsync();
3. Filtering by IndexTag
var invoices = db.TempDocumentData
.Where(d => d.IndexTag.StartsWith("Invoice-"))
.ToList();
π― Conclusion
This Designer snapshot is a vital part of the EF Core migration pipeline. By defining the IndexTag column addition in TempDocumentData, it empowers the application to classify and search temporary documents more efficiently. Keep this file in sync with your domain model; any manual edits can break future migrations.
β Tip: Always review auto-generated designer files to ensure that EF Coreβs snapshot matches your intent and domain classes.