📄 Documentation: 20240131151348_AddPWDColumnsToEmployeeTable.Designer.cs
🗂 Table of Contents
- Overview & Purpose
- Context: EF Core Migrations
- Key Method:
BuildTargetModel - Spotlight:
EmployeeEntity & New Columns - Model Snapshot & Entity Mapping
- How to Apply This Migration
- UML Diagram (Mermaid)
- Conclusion
1. Overview & Purpose 📋
This file is an auto‑generated EF Core migration designer class that captures the state of your EF Core model after applying the migration named:
AddPWDColumnsToEmployeeTable
Timestamp:2024-01-31 15:13:48
- Role: EF Core uses this snapshot to compute schema differences when you add future migrations.
- Primary Change: Addition of two new columns—
PWResetandPWResetDate—to the Employee table.
2. Context: EF Core Migrations 🔧
[DbContext(typeof(IrbyContext))]
[Migration("20240131151348_AddPWDColumnsToEmployeeTable")]
partial class AddPWDColumnsToEmployeeTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// … entire model snapshot …
}
}
- DbContext:
IrbyContext - MigrationId:
"20240131151348_AddPWDColumnsToEmployeeTable" - Designer File: Contains only the
BuildTargetModelmethod—no Up/Down scripts here.
When you run:
dotnet ef migrations add AddPWDColumnsToEmployeeTable
EF Core generates two files:
20240131151348_AddPWDColumnsToEmployeeTable.cs➞ ContainsUp()andDown()methods.20240131151348_AddPWDColumnsToEmployeeTable.Designer.cs➞ This snapshot.
3. Key Method: BuildTargetModel 🚀
- Purpose: Reconstructs your EF Core model in code so EF can diff it against previous snapshots.
- Structure:
- Global Annotations
modelBuilder .HasAnnotation("ProductVersion", "7.0.7") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - Entity Definitions
For each domain class (Asset,Employee,Job, etc.), there is a call:modelBuilder.Entity("Namespace.DomainClasses.MyEntity", b => { b.Property<...>("PropertyName")... b.HasKey("KeyProperty"); b.ToTable("MyEntity", "schema"); // indexes, relationships, discriminator (for TPH), etc. }); - Relationships & Navigation
After all entities are defined, there are.HasOne()and.WithMany()calls to wire up FKs.
- Global Annotations
4. Spotlight: Employee Entity & New Columns 🔑
Full Mapping Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => {
b.Property<Guid>("EmployeeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// … existing columns …
// 🔥 New columns added by this migration:
b.Property<bool>("PWReset")
.HasColumnType("bit");
b.Property<DateTime>("PWResetDate")
.HasColumnType("datetime2");
// … rest of mapping …
b.HasKey("EmployeeId");
b.HasIndex("DepartmentId");
b.HasIndex("JdeNumber")
.IsUnique()
.HasFilter("[JdeNumber] IS NOT NULL");
b.HasIndex("JobId");
b.HasIndex("RoleId");
b.ToTable("Employee", "irby");
});
💡 Summary of New Columns
| Column | CLR Type | SQL Type | Nullable | Default Value | Description |
|---|---|---|---|---|---|
PWReset |
bool |
bit |
NO |
false |
Indicates if the employee needs a reset. |
PWResetDate |
DateTime |
datetime2 |
NO |
0001-01-01 |
Timestamp when reset was triggered. |
Note: In your
Up()method (not shown here), EF will typically scaffold:migrationBuilder.AddColumn<bool>( name: "PWReset", schema: "irby", table: "Employee", nullable: false, defaultValue: false); migrationBuilder.AddColumn<DateTime>( name: "PWResetDate", schema: "irby", table: "Employee", nullable: false, defaultValue: new DateTime(yyyy, mm, dd, …));
5. Model Snapshot & Entity Mapping 🗺️
Beyond Employee, this file records the entire domain model, including:
- Asset Hierarchy (TPH):
Asset(base) →Computer,DeskPhone,MobileDevice, ... - Reference Entities:
Department,Role,Permissions,FieldOffice,Job,Customer,GeneralLedger, etc. - Many-to-many / Linking:
LinkUserRole,LinkRolePermission - Lookup / Reporting Views:
AuditReport,LicenseReport,DirectorLeaseInfo, etc. - External Sync Tables:
ODSCustomer,ODSEmployee,ODSJob
Each entity block includes:
- Column definitions with types & nullability
- Primary keys via
.HasKey() - Indexes via
.HasIndex() - Schema and table name via
.ToTable("Name","schema") - Inheritance (TPH) with
.HasDiscriminator()
6. How to Apply This Migration 🛠️
- Add the migration (already done):
dotnet ef migrations add AddPWDColumnsToEmployeeTable - Review the generated
.csUp/Down script. - Update the database:
dotnet ef database update - Verify in SQL Server that
irby.Employeehas the two new columns:EXEC sp_help 'irby.Employee';
7. UML Diagram (Mermaid) 📈
classDiagram
class Employee {
+Guid EmployeeId
+string FirstName
+string LastName
+string JdeNumber
+bool PWReset <<new>>
+DateTime PWResetDate <<new>>
+... // other properties
}
Employee --> Department : FK DepartmentId
Employee --> Job : FK JobId
Employee --> Role : FK RoleId
8. Conclusion 🎉
- This Designer file is an EF Core internal snapshot reflecting your complete domain model after adding the password‑reset columns.
- It underpins subsequent migrations by providing a baseline for model‑to‑database diffs.
- You should normally not modify it by hand—treat it as a read‑only artifact generated by the EF tooling.
Happy coding! 🛡️🚀