📄 Documentation: 20240201163255_UpdateEmployeeTableWithNewColumns.Designer.cs
🗂 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- File Structure & Key Components
BuildTargetModelMethod Deep Dive- Data Models Overview
- Usage Examples
- Simplified UML Diagram
- Conclusion
1. 📖 Overview & Purpose
This file is an auto-generated snapshot of your EF Core model after applying the migration named
UpdateEmployeeTableWithNewColumns (timestamp 20240201163255). It lives under:
IrbyImaging.DbContext/
└─ Migrations/
└─ 20240201163255_UpdateEmployeeTableWithNewColumns.Designer.cs
Why it exists
- EF Core uses it to track the target state of your database schema.
- It enables subsequent migrations to compute differences (deltas) between the current model and the desired one.
⚠️ Never manually edit this file. Changes will be overwritten whenever a new migration is scaffolded.
2. ⚙️ Dependencies & Technologies
| Package / Technology | Purpose |
|---|---|
| Microsoft.EntityFrameworkCore (v7.0.7) | Core ORM framework |
| Microsoft.EntityFrameworkCore.Migrations | Migration generation & execution |
| Microsoft.EntityFrameworkCore.Infrastructure | Internal services for model building |
| Microsoft.EntityFrameworkCore.Metadata | Model metadata abstractions |
| Microsoft.EntityFrameworkCore.Storage.ValueConversion | CLR↔Database type converters |
SQL Server Provider (UseIdentityColumns) |
SQL Server–specific identity configuration |
| .NET 7.0 | Target framework |
3. File Structure & Key Components
3.1 Auto‑Generated Notice
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
…
// #nullable disable
<auto-generated />: Indicates that this file is produced by tooling (EF Core).#nullable disable: Disables nullable-reference annotations for backward compatibility.
3.2 Partial Migration Class
namespace IrbyImaging.DbContext.Migrations
{
[DbContext(typeof(IrbyContext))]
[Migration("20240201163255_UpdateEmployeeTableWithNewColumns")]
partial class UpdateEmployeeTableWithNewColumns
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// … model snapshot …
}
}
}
[DbContext(typeof(IrbyContext))]
Binds this migration to yourIrbyContext.[Migration("…")]
Uniquely identifies the migration by timestamp and name.partial class
Splits migration logic (Up/Down) from this snapshot of the model.
4. BuildTargetModel Method Deep Dive
The heart of this file is the override:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
EF Core invokes this to rebuild a Model in memory representing the final schema state.
4.1 ModelBuilder Initialization
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
- ProductVersion: Tracks EF Core version to maintain compatibility.
- MaxIdentifierLength: Database object name length limit (128 for SQL Server).
- UseIdentityColumns: Globally configures auto–increment keys (IDENTITY) for SQL Server.
4.2 Entity Definitions & Configuration
For each domain class, EF Core emits a block:
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => {
// Property mapping
b.Property<Guid>("EmployeeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("nvarchar(max)");
// … more properties …
// Key
b.HasKey("EmployeeId");
// Indexes
b.HasIndex("JdeNumber")
.IsUnique()
.HasFilter("[JdeNumber] IS NOT NULL");
// Table mapping
b.ToTable("Employee", "irby");
});
b.Property<T>("PropName")
Maps CLR propertyPropName→ column of typeT.- Fluent configuration
.ValueGeneratedOnAdd()→ auto-generated on insert.IsRequired()→ NOT NULL.HasColumnType("…")→ explicit SQL type
4.3 Keys, Indexes & Constraints
| Operation | Syntax | Effect |
|---|---|---|
| Primary Key | b.HasKey("Id") |
Defines PRIMARY KEY (Id) |
| Unique Index | b.HasIndex("Imei").IsUnique().HasFilter("[Imei] IS NOT NULL") |
Unique constraint on non-null IMEI |
| Foreign Key | Defined later in relationships section | Enforces referential integrity |
4.4 Table & Schema Mapping
b.ToTable("Asset", "irby");
"Asset"→ table name"irby"→ schema (custom, avoidsdbo)
If schema is omitted, EF uses the database default (often dbo).
4.5 Inheritance & Discriminators
Table‑Per‑Hierarchy (TPH) for Asset and its subtypes:
// Base Asset
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
b.HasDiscriminator<string>("Discriminator")
.HasValue("Asset");
});
// Derived type
modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b => {
b.HasBaseType("IrbyImaging.DomainClasses.Asset");
b.HasDiscriminator().HasValue("Computer");
});
Discriminatorcolumn holds the subtype name (e.g.,"Computer","Monitor","Dock").
4.6 Relationship Mapping
After all entities, EF emits relationship definitions:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
b.HasOne("IrbyImaging.DomainClasses.Employee", "Owner")
.WithMany("Assets")
.HasForeignKey("OwnerId");
// … other FKs …
});
HasOne(PrincipalType, NavigationName)WithMany(CollectionName)HasForeignKey("FKColumn")OnDelete(DeleteBehavior.Cascade)(where configured)
Navigation properties are also recorded via .Navigation("…").
5. 🗃️ Data Models Overview
This snapshot covers a wide set of domain classes (75+), including but not limited to:
| Category | Representative Entities |
|---|---|
| Asset Management | Asset, Computer, MobileDevice, OfficePrinter, Dock |
| People & Roles | Employee, Department, Role, LinkUserRole, Permissions |
| Job & Sites | Job, FieldOffice, Customer, ContractTypeDetails |
| Documents & Imaging | DocumentImage, BlobData, TempDocumentData, AssetHistory |
| Auditing & Logging | AuditDetail, AuditReport, Ticket, Update |
| Time Tracking | TimeSheetEntry, TimeEntryType |
| Third‑Party Reporting | ODSEmployee, ODSJob, IPMMigration, LytxTemplate |
Each entity is mapped to its corresponding table (and schema) and includes columns, constraints, and relationships.
6. 🛠️ Usage Examples
6.1 Applying the Migration
With the EF Core CLI:
# From your project root:
dotnet ef database update 20240201163255_UpdateEmployeeTableWithNewColumns
- Updates your database schema to match the
BuildTargetModelstate.
6.2 Rolling Back a Migration
# Roll back to the previous migration (e.g., 20240101120000_PreviousMigration)
dotnet ef database update 20240101120000_PreviousMigration
- Executes the Down method of
20240201163255_UpdateEmployeeTableWithNewColumnsto revert changes.
7. 📐 Simplified UML Diagram
+----------------------+
| IrbyContext |
| (DbContext) |
+----------+-----------+
|
| Applies
v
+------------------------------------------------+
| Migration: UpdateEmployeeTableWithNewColumns |
+------------------------------------------------+
| - BuildTargetModel(modelBuilder) |
+------------------------------------------------+
|
v
+----------------+ +-----------------+ +----------------+
| Employee | | Asset | | Job |
+----------------+ +-----------------+ +----------------+
| EmployeeId PK | | Id PK | | JobId PK |
| FirstName | | Category | | JdeNumber (U) |
| LastName | | Discriminator | | Status |
| ... | | ... | | ... |
+----------------+ +-----------------+ +----------------+
| |
| owns | derived
v v
+----------------+ +-----------------+
| TimeSheetEntry | | Computer |
+----------------+ +-----------------+
| TimeSheetEntryId| | AssetNumber |
| HoursWorked | | OperatingSystem |
+----------------+ +-----------------+
8. 🔚 Conclusion
UpdateEmployeeTableWithNewColumns.Designer.csis a read‑only snapshot of your EF Core model post‑migration.- It captures entities, properties, constraints, indexes, and relationships in fluent API form.
- Use the standard EF Core commands (
add,update,removemigrations) to safely evolve your schema—do not hand‑edit this file.
Happy coding! 🚀