📑 Migration Documentation: 20230710174948_AddIsHrColumn.Designer.cs
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- EF Core Migration Basics
BuildTargetModelMethod- Key Functional Areas
5.1. Entities & Tables
5.2. Properties & Columns
5.3. TPH Inheritance & Discriminator
5.4. Relationships & Indexes - The New
IsHrColumn - Applying the Migration
- Usage Examples
- Simplified UML Diagram
- Conclusion
1. Overview & Purpose
🚀 What is this file?
This .Designer.cs file is an auto-generated EF Core model snapshot that reflects the database schema after the AddIsHrColumn migration has been applied. It does not contain the Up()/Down() logic itself, but rather a full description of the model in code, used by EF Core to compute future schema diffs.
Primary Purpose
- Capture the state of all entities, tables, columns, keys, constraints, indexes, and relationships at this migration point.
- Include the newly added
IsHrboolean property on certain tables.
2. Dependencies & Technologies
| Technology | Version |
|---|---|
| .NET SDK | 7.0.7 |
| Entity Framework Core | 7.0.7 |
| Microsoft.EntityFrameworkCore.SqlServer | 7.0.7 |
| C# Language | 10.0 (nullable disabled) |
3. EF Core Migration Basics
- Code-based Migration (
.csfile)- Contains
Up()andDown()methods to apply or revert schema changes.
- Contains
- Model Snapshot (
.Designer.csfile)- Stores a fluent‑API reproduction of the entire EF model at that point.
- Enables EF to compare the current model against future changes.
Note: You normally do not edit this file manually. EF generates it when you run
dotnet ef migrations add.
4. BuildTargetModel Method
This method re-creates the entire database schema in code:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// Global annotations
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// Use SQL Server Identity columns
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// Declare each entity…
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { … });
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentAttribute", b => { … });
// …and so on for all domain classes.
}
- Annotations: Capture provider and version details.
- Identity Columns: Configures PK generation for SQL Server.
- Entity Declarations: Defines tables, columns, keys, indexes, relationships, and inheritance.
5. Key Functional Areas
5.1 Entities & Tables
Below is a sample of the 50+ entities described.
| Entity Class | Schema | Table Name |
|---|---|---|
IrbyImaging.DomainClasses.Asset |
irby | Asset |
IrbyImaging.DomainClasses.DocumentAttribute |
irby | DocumentAttribute |
IrbyImaging.DomainClasses.DocumentCategory |
irby | DocumentCategory |
IrbyImaging.DomainClasses.TempDocumentData |
irby | TempDocumentData |
IrbyImaging.DomainClasses.Employee |
irby | Employee |
IrbyImaging.DomainClasses.TimeSheetEntry |
irby | TimeSheetEntry |
| …and many more… |
Tip: Use
modelBuilder.HasDefaultSchema("irby")patterns to group all tables under theirbyschema.
5.2 Properties & Columns
Every property is mapped with explicit SQL types and column options:
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
- Key Types:
uniqueidentifier,int,bit,decimal(18,2),datetime2,datetimeoffset,varbinary(max), etc. - Value Generation:
.ValueGeneratedOnAdd()/.UseIdentityColumn()for PKs. - Requiredness:
.IsRequired()on non-nullable CLR types.
5.3 TPH Inheritance & Discriminator
Table-per-Hierarchy (TPH) is used for the Asset class hierarchy:
- A single
Assettable holds allAsset-derived types (Computer, MobileDevice, etc.). - A hidden
Discriminatorcolumn tells EF which subtype each row represents.
modelBuilder.Entity("Asset", b =>
{
b.HasDiscriminator<string>("Discriminator")
.HasValue("Asset"); // Base class value
… .HasValue("Computer") // Derived types
.HasValue("MobileDevice")
.HasValue("SafetyEquipment");
});
5.4 Relationships & Indexes
Relationships are defined via HasOne / WithMany and foreign keys:
b.HasOne("FieldOffice", "FieldOffice")
.WithMany("Assets")
.HasForeignKey("FieldOfficeId");
b.HasIndex("FieldOfficeId");
- Navigation Properties
FieldOffice → AssetsEmployee → AssetsTicket → Updates, etc.
- Indexes
- Many foreign keys automatically get supporting indexes.
6. The New IsHr Column
With this migration, a new column IsHr is added to three tables:
| Table (Entity) | Schema | Column Type | Default in Model |
|---|---|---|---|
DocumentAttribute |
irby |
bit |
New |
DocumentCategory |
irby |
bit |
New |
TempDocumentData |
irby |
bit |
New |
Why
IsHr?
A boolean flag to denote Human‑Resources relevance.
true→ Document is HR‑relatedfalse→ Non‑HR document
7. Applying the Migration
- Add Migration (already executed):
dotnet ef migrations add AddIsHrColumn --context IrbyContext - Update Database:
dotnet ef database update --context IrbyContext - Verify: Check the updated schema in SQL Server:
SELECT TOP 5 IsHr FROM irby.DocumentAttribute;
8. Usage Examples
8.1 Toggle IsHr in C#
using var context = new IrbyContext();
// Mark an attribute as HR
var attr = await context.DocumentAttributes.FindAsync(myAttrId);
attr.IsHr = true;
await context.SaveChangesAsync();
8.2 Query HR‑Only Records
var hrAttributes = context.DocumentAttributes
.Where(a => a.IsHr)
.ToList();
9. Simplified UML Diagram
+------------------------+
| DocumentAttribute |
+------------------------+
| Id : Guid |
| Name : string |
| IsAvailable : bool |
| … |
| IsHr : bool | ← New!
+------------------------+
+------------------------+
| DocumentCategory |
+------------------------+
| Id : Guid |
| Name : string |
| Description : string |
| IsDeleted : bool |
| IsHr : bool | ← New!
+------------------------+
+------------------------+
| TempDocumentData |
+------------------------+
| TempDocumentDataId :Guid |
| BatchId : Guid |
| FileName : string |
| IsIndexed : bool |
| IsHr : bool | ← New!
+------------------------+
10. Conclusion
- This model snapshot enables EF Core to track the state of your schema after adding the
IsHrcolumn. - Do not edit manually—changes are managed by EF migrations.
- Whenever you add or modify entities, run
dotnet ef migrations add <Name>to regenerate this snapshot. - Use the new
IsHrflag in your LINQ queries or business logic to handle HR‑specific document processing.
🎉 Happy coding and efficient schema management!