π Documentation: 20240201193312_UpdateEmployeeTableWithNewColumns4.Designer.cs
File Path:
IrbyImaging.DbContext/Migrations/20240201193312_UpdateEmployeeTableWithNewColumns4.Designer.cs
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Configuration
- π Data Models (Entities)
- π Relationships & Constraints
- π Inheritance & TPH Strategy
- π Usage & Integration
- π Sample Commands
- π UML Diagram (Mermaid)
- π Conclusion
π Overview & Purpose
This Designer file is an auto-generated snapshot of your Entity Framework Core model after applying the migration named UpdateEmployeeTableWithNewColumns4. It is used internally by EF Core to:
- Reconstruct the target database schema (tables, columns, keys, relationships).
- Compare model snapshots during migrations apply or rollback.
- Drive the SQL generation that brings your database in sync with your C# model.
β οΈ Note: You normally should not edit this file by hand.
Changes are pushed here automatically each time you add a new migration.
π οΈ Dependencies & Technologies
| Technology / Package | Version | Purpose |
|---|---|---|
| .NET SDK | 7.0.7 | Runtime & compilation target |
| EntityFrameworkCore | 7.0.* | ORM mapping & migrations |
| Microsoft.EntityFrameworkCore.SqlServer | 7.0.* | SQL Server provider |
| C# | 11 | Language |
| SQL Server | 2019+ | Database |
Additional EF Core namespaces imported:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
π§ Migration Configuration
Attributes & Metadata
[DbContext(typeof(IrbyContext))]
[Migration("20240201193312_UpdateEmployeeTableWithNewColumns4")]
partial class UpdateEmployeeTableWithNewColumns4 : Migration
{
// ...
}
[DbContext]links the migration to yourIrbyContext.[Migration]attribute carries the timestamped name that EF uses for ordering.
BuildTargetModel Method
At the core of this file is the override:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// β Configuration for dozens of entitiesβ¦
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
b.Property<Guid>("EmployeeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// β¦ many properties β¦
b.HasKey("EmployeeId");
b.HasIndex("JdeNumber")
.IsUnique()
.HasFilter("[JdeNumber] IS NOT NULL");
b.ToTable("Employee", "irby");
});
// β¦ additional Entity configurations β¦
#pragma warning restore 612, 618
}
Responsibilities:
- Defines global annotations (provider version, identifier length).
- Registers identity column strategy for SQL Server.
- Iterates through all entities, specifying:
- Properties (type,
IsRequired, conversions). - Keys & Indexes.
- Table mappings & schema.
- Discriminators for inheritance (TPH).
- Properties (type,
π Data Models (Entities)
This snapshot includes 70+ entity configurations. Below we focus on the Employee entity and a few other highlights.
Key Entity: Employee
| Column | CLR Type | SQL Type | Required | Notes |
|---|---|---|---|---|
| EmployeeId | Guid |
uniqueidentifier |
Yes | Primary Key, identity-style |
AzureUserId |
Guid |
uniqueidentifier |
No | |
FirstName |
string |
nvarchar(max) |
No | |
LastName |
string |
nvarchar(max) |
No | |
| JdeNumber | string |
nvarchar(450) |
No | Unique index if not NULL |
Email |
string |
nvarchar(max) |
No | |
EmploymentStartDate |
DateTime? |
datetime2 |
No | |
| Status | string |
nvarchar(max) |
Yes | |
JobId |
Guid |
uniqueidentifier |
Yes | FK β Job |
DepartmentId |
Guid? |
uniqueidentifier |
No | FK β Department |
RoleId |
Guid? |
uniqueidentifier |
No | FK β Role |
π Primary Key: EmployeeId
π Indexes:
- Unique on
JdeNumber([JdeNumber] IS NOT NULL) - Foreign keys:
JobId,DepartmentId,RoleId
Selected Entity Configurations
| Entity | Table | Schema | Notes |
|---|---|---|---|
IrbyImaging.DomainClasses.Job |
Job |
irby |
Unique index on JdeNumber |
IrbyImaging.DomainClasses.Asset |
Asset |
irby |
TPH root, Discriminator column |
IrbyImaging.DomainClasses.Department |
Department |
irby |
Soft-delete flag IsDeleted |
IrbyImaging.DomainClasses.Role |
Role |
irby |
Many-to-many via LinkUserRole |
IrbyImaging.DomainClasses.AssetModel |
AssetModel |
irby |
FK β AssetManufacturer |
| ⦠and many more⦠|
π Relationships & Constraints
- One-to-Many
- Employee β Job (
JobId) - Department β Employees
- Role β LinkUserRole β Employee
- Employee β Job (
- Many-to-Many
RoleβPermissionsviaLinkRolePermissionEmployeeβRoleviaLinkUserRole
- Cascade Deletes
- Removing a
Jobcascades to relatedEmployees. - Removing a
Rolecascades to itsPermissionslinks.
- Removing a
- Indexes
- Unique:
Employee(JdeNumber),Job(JdeNumber),FieldOffice(JdeNumber),MobileDevice(Imei) - Filters ensure NULLable columns do not break uniqueness.
- Unique:
π Inheritance & TPH Strategy
The Asset entity uses a TableβperβHierarchy approach:
- Discriminator column (
string) distinguishes subtypes:ComputerMobileDeviceDeskPhoneDockMonitorOfficePrinterPrinterNetworkEquipmentSafetyEquipment
- All subtypes share the
Assettable. - EF Coreβs
UseTphMappingStrategy()is invoked by default.
π Usage & Integration
-
Adding a Migration:
dotnet ef migrations add UpdateEmployeeTableWithNewColumns4 \ --context IrbyContext -
Applying to Database:
dotnet ef database update \ --context IrbyContext -
Reviewing SQL Script:
dotnet ef migrations script 20240201193312_UpdateEmployeeTableWithNewColumns4
The Designer file will be updated automatically whenever you scaffold a new migration.
π Sample Commands
# Scaffold a new migration based on model changes
dotnet ef migrations add UpdateEmployeeTableWithNewColumns4
# Apply pending migrations to the DB
dotnet ef database update
# Generate full migration SQL for review
dotnet ef migrations script
π UML Diagram (Mermaid)
classDiagram
class Employee {
+Guid EmployeeId
+string FirstName
+string LastName
+string JdeNumber
+string Status
}
class Department {
+Guid DepartmentId
+string Name
}
class Job {
+Guid JobId
+string Name
+string JdeNumber
}
class Role {
+Guid RoleId
+string Name
}
Employee --> Department : DepartmentId
Employee --> Job : JobId
Employee --> Role : RoleId
π Conclusion
This Designer snapshot is the backbone of your EF Core migration UpdateEmployeeTableWithNewColumns4. It captures the complete state of your modelβentities, properties, indexes, relationships, inheritance strategiesβso EF can generate and validate your database schema.
π§ Tip: Keep your domain classes and migrations in sync. Always let EF Core manage these Designer files to ensure smooth upgrades and rollbacks.
Happy coding! πβ¨