📖 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Class:
NewIsHRColumn - Key Entities & New IsHR Columns
- TPH Inheritance:
AssetHierarchy - Relationships & Navigation Properties
- Usage & Applying the Migration
- Conclusion
🎯 Overview & Purpose
This auto‑generated designer file represents the target model snapshot for the Entity Framework Core migration 20230711142328_NewIsHRColumn.
It captures how the database schema should look after applying the migration that introduces a new IsHR flag to several document‑related tables.
Key goals:
- Introduce a boolean
IsHRcolumn for document filtering at the database level - Ensure the EF Core model matches the updated schema for Code‑First migrations
- Maintain existing tables, indexes, relationships, and inheritance mappings
⚙️ Dependencies & Technologies
| Technology / Package | Version | Purpose |
|---|---|---|
| .NET SDK | 7.0.x | Runtime & Compiler |
| Microsoft.EntityFrameworkCore | 7.0.7 | ORM Core |
| Microsoft.EntityFrameworkCore.SqlServer | 7.0.7 | SQL Server provider |
| Microsoft.EntityFrameworkCore.Tools | 7.0.7 | Migrations & CLI tooling |
🛠 Migration Class: NewIsHRColumn
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace IrbyImaging.DbContext.Migrations
{
[DbContext(typeof(IrbyContext))]
[Migration("20230711142328_NewIsHRColumn")]
partial class NewIsHRColumn
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// ...
}
}
}
🧐 What Is a Designer File?
- Designer files (
*.Designer.cs) are automatically generated by EF Core to snapshot the model structure. - They complement the migration’s
Up()/Down()methods by providing the full target schema. - Do not hand‑edit: modifications should happen in your domain classes or the migration code itself.
🔨 BuildTargetModel(ModelBuilder) Method
- Called by EF Core during
dotnet ef database updateto reconstruct the model in memory. - The
ModelBuilderis configured with:- Entity definitions
- Property types & constraints
- Table mappings
- Indexes & keys
- Relationships & navigations
- Inheritance strategies
🌐 Global Model Annotations & Conventions
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
- ProductVersion: tags the EF Core version used
- MaxIdentifierLength: ensures table/column names fit within SQL Server limits
- UseIdentityColumns: switch to IDENTITY columns for key generation
🔑 Key Entities & New IsHR Columns
This migration introduces a new boolean flag IsHR to facilitate human‑resources filtering in the document management module.
📋 Summary of IsHR Additions
| Entity | Table Name | New Column | Type | Nullable? |
|---|---|---|---|---|
DocumentAttribute |
irby.DocumentAttribute |
IsHR |
bit |
No |
DocumentCategory |
irby.DocumentCategory |
IsHR |
bit |
No |
DocumentType |
irby.DocumentType |
IsHR |
bit |
No |
DocumentImage |
irby.DocumentImage |
IsHR |
bit |
No |
TempDocumentData |
irby.TempDocumentData |
IsHR |
bit |
No |
Why
IsHR?
- Allows dynamic filtering: e.g. show only HR documents in a dashboard
- Enhances security & segregation of sensitive content
💻 Sample Code Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentAttribute", b =>
{
b.HasKey("Id");
b.ToTable("DocumentAttribute", "irby");
// ... existing columns ...
b.Property<bool>("IsHR")
.HasColumnType("bit")
.IsRequired();
});
🏗️ TPH Inheritance: Asset Hierarchy
The Asset entity uses Table‑Per‑Hierarchy (TPH) to map multiple C# types into a single database table:
classDiagram
Asset <|-- Computer
Asset <|-- DeskPhone
Asset <|-- Dock
Asset <|-- MobileDevice
Asset <|-- Monitor
Asset <|-- NetworkEquipment
Asset <|-- OfficePrinter
Asset <|-- Printer
Asset <|-- SafetyEquipment
- A single table
irby.Assetholds all derived types - A Discriminator column drives polymorphism
- Derived classes may introduce extra columns
🔗 Relationships & Navigation Properties
EF Core configures foreign‑keys and navigations automatically:
- Asset → FieldOffice (
FieldOfficeId) - Asset → AssetModel (
ModelId) - Asset → Employee (Owner, via
OwnerId) - AssetModel → Manufacturer (
MakeId) - Employee → Job (
CurrentJobId) - Various staging & detail tables linked by GUIDs
Example:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { b.HasOne("FieldOffice") .WithMany("Assets") .HasForeignKey("FieldOfficeId"); });
▶️ Usage & Applying the Migration
- Add & update migration (already done):
dotnet ef migrations add NewIsHRColumn - Apply to database:
dotnet ef database update - Verify new
IsHRcolumns appear in SQL Server Management Studio or via query:SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DocumentAttribute' AND COLUMN_NAME = 'IsHR';
🏁 Conclusion
- The
20230711142328_NewIsHRColumn.Designer.csfile fully describes the post‑migration schema. - Key addition: the
IsHRboolean on multiple tables to support HR‑specific document workflows. - As part of EF Core’s code‑first approach, this snapshot ensures consistency between your C# model and the SQL Server schema.
Happy coding! 🚀