π Migration Documentation:
AddNewColumnsEmployeeAndAuditTable.Designer.cs
IrbyImaging.DbContext/Migrations/20230828165122_AddNewColumnsEmployeeAndAuditTable.Designer.cs
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models Overview
- Sample Code Snippets
- UML Diagram (Asset Hierarchy)
- Usage & Applying the Migration
- Conclusion
1. Overview & Purpose
This file is an auto-generated designer class for the Entity Framework Core migration AddNewColumnsEmployeeAndAuditTable.
- π Role: Keeps a snapshot of the EF Core model after the migration is applied.
- π When It Runs: During
dotnet ef migrations addandupdate-database. - π― Why It Exists: EF Core uses it to compare your C# model against the database schema, scaffold future migrations, and apply changes reliably.
2. Dependencies & Technologies
| Technology / Package | Version / Notes |
|---|---|
| Microsoft.EntityFrameworkCore | 7.0.7 |
| Microsoft.EntityFrameworkCore.SqlServer | Underlying relational provider |
| .NET 7.0 | Target framework |
| C# / Nullable Disabled | #nullable disable at top of file |
3. Key Functional Areas
3.1 BuildTargetModel Method
[DbContext(typeof(IrbyContext))]
[Migration("20230828165122_AddNewColumnsEmployeeAndAuditTable")]
partial class AddNewColumnsEmployeeAndAuditTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// ... entity configurations follow ...
}
}
- BuildTargetModel: Core method where all entities, their properties, keys, indexes, relationships, and table mappings are defined.
- Annotations:
"ProductVersion"locks the EF Core version."Relational:MaxIdentifierLength"for SQL Server limits.
- UseIdentityColumns: Enables SQL Server identity (autoβincrement) on key properties by convention.
3.2 Entity Mappings
- Each call to
modelBuilder.Entity("Namespace.ClassName", b => { β¦ })configures a table. - Table & Schema:
- e.g.
b.ToTable("Employee", "irby");maps theEmployeeentity toirby.Employee.
- e.g.
- Property Configuration:
.HasColumnType("uniqueidentifier")βGuidon SQL Server..IsRequired()βNOT NULL..ValueGeneratedOnAdd()βIDENTITYor computed by database onINSERT.
3.3 Relationships & Foreign Keys
- Defined at the bottom via
.HasOne(β¦)/.WithMany(β¦). - Example:
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b => { b.HasOne("IrbyImaging.DomainClasses.Department", "Department") .WithMany() .HasForeignKey("DepartmentId"); }); - Cascade Deletes:
.OnDelete(DeleteBehavior.Cascade)ensures child rows are removed when parent is deleted.
3.4 Indexes & Constraints
- Primary Key:
b.HasKey("EmployeeId"); - Unique Index:
b.HasIndex("JdeNumber") .IsUnique() .HasFilter("[JdeNumber] IS NOT NULL"); - Standard Index:
b.HasIndex("RoleId");
3.5 Inheritance & TPH Mapping
- Table-Per-Hierarchy (TPH) for
Assetand subβtypes (Computer,MobileDevice, etc.). - Discriminator Column:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { b.HasDiscriminator<string>("Discriminator") .HasValue("Asset"); b.UseTphMappingStrategy(); }); - Subclasses override
.HasDiscriminator().HasValue("SubTypeName").
4. Data Models Overview
Below is a subset of the dozens of domain entities configured by this migration.
| Entity Name | Table Name | Schema | Key Property | Notes |
|---|---|---|---|---|
| Asset | Asset | irby | Id (uniqueidentifier) | Base class for many assets. |
| Employee | Employee | irby | EmployeeId (Guid) | Has indexes on JdeNumber, Dept, Role. |
| AuditDetail | AuditDetail | irby | AuditDetailId (Guid) | New audit trail table. |
| CarrierTypeDetail | CarrierTypeDetail | irby | Id (Guid) | FK β CarrierType. |
| TimeSheetEntry | TimeSheetEntry | irby | TimeSheetEntryId | FK β Employee, TimeEntryType. |
| β¦ | β¦ | β¦ | β¦ | β¦ |
Tip: This migration adds new columns and new tables for Employee and Audit tracking, reflected here in the expanded model snapshot.
5. Sample Code Snippets
Mapping a Simple Entity
modelBuilder.Entity("IrbyImaging.DomainClasses.Department", b =>
{
b.Property<Guid>("DepartmentId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("DepartmentId");
b.ToTable("Department", "irby");
});
Defining a Foreign Key Relationship
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
b.HasOne("IrbyImaging.DomainClasses.Employee", "Owner")
.WithMany("Assets")
.HasForeignKey("OwnerId");
});
6. UML Diagram (Asset Hierarchy)
Below is a simplified PlantUML snippet illustrating the Asset inheritance:
@startuml
abstract class Asset {
+Guid Id
+string Category
+DateTimeOffset PurchaseDate
}
class Computer extends Asset {
+string AssetNumber
+int OperatingSystemId
}
class MobileDevice extends Asset {
+string Imei
+bool IsTelogis
}
Asset <|-- Computer
Asset <|-- MobileDevice
@enduml
7. Usage & Applying the Migration
- Add Migration
dotnet ef migrations add AddNewColumnsEmployeeAndAuditTable - Update Database
dotnet ef database update - Review Generated SQL
- Inspect the corresponding
*.sqlto see DDL for new columns/tables.
- Inspect the corresponding
π After applying, your database schema will match the model snapshot defined herein.
8. Conclusion
This designer file is a model snapshot that ensures EF Core can:
- Track your domain model structure.
- Scaffold future migrations accurately.
- Reconstruct the model when updating or rolling back.
Note: You typically do not edit this file manually. Changes in your C# domain classes β
dotnet ef migrations addβ this file will be regenerated.
β¨ Happy Coding!
This documentation should serve as a reference for understanding how EF Core has configured your model and how the new Employee & Audit tables are integrated.