📚 Migration Documentation
File: IrbyImaging.DbContext/Migrations/20240724182925_AddAutoIncrementTimesheetNumber.Designer.cs
Namespace: IrbyImaging.DbContext.Migrations
Generated: EF Core 7.0.7 for SQL Server
📋 Table of Contents
- ✨ Overview & Purpose
- ⚙️ Dependencies & Technologies
- 🏗️ Key Functional Areas
- 🔍 Migration Details
- 🗄️ Domain Entities Summary
- 🖼️ Simplified UML Class Diagram
- 🚀 Usage & Applying Migration
- 🧪 Testing & Verification
- 📘 Further Reading & References
✨ Overview & Purpose
This auto‑generated designer file captures the target database model after applying the migration 20240724182925_AddAutoIncrementTimesheetNumber. Its primary goal is to:
- Reflect a new Identity / Auto‑Increment setting for the
TimesheetNumbercolumn on theMechanicTimesheettable. - Maintain a snapshot of all domain entities, relationships, indexes, and SQL Server conventions in use.
Why Designer.cs?
EF Core splits a migration into two files:
Up/Downlogic (shows DDL changes)- Designer (this one)—captures the entire model structure as of this migration.
⚙️ Dependencies & Technologies
| Technology | Version | Purpose |
|---|---|---|
| .NET | 7.0 | Runtime framework |
| Entity Framework Core | 7.0.7 | ORM & migration engine |
| SQL Server | ≥2016 | Relational database provider |
| C# / Visual Studio | C# 11 / VS 2022 | Development environment |
🏗️ Key Functional Areas
- Model Snapshot
- Declares all entities, properties, keys, indexes, and relationships.
- Identity Columns
- Applies
UseIdentityColumns()at model level (SQL Server identity).
- Applies
- Entity‑Inheritance (TPH)
- Assets and its derived classes (
Computer,MobileDevice, etc.) share a single table with discriminator.
- Assets and its derived classes (
- New Auto‑Increment
- Adds identity configuration to
MechanicTimesheet.TimesheetNumber.
- Adds identity configuration to
🔍 Migration Details
4.1 BuildTargetModel Method
The heart of the designer file is:
protected override void BuildTargetModel(ModelBuilder modelBuilder) {
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// Globally enable SQL Server identity columns
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// …entity configurations…
#pragma warning restore 612, 618
}
HasAnnotation: Records EF Core version and identifier limits.UseIdentityColumns: SwitchesValueGeneratedOnAdd()properties to SQL ServerIDENTITYcolumns by default.
4.2 Identity Columns Convention
By calling
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
all integer properties marked with .ValueGeneratedOnAdd() will use IDENTITY(1,1) instead of the legacy Sequence behavior.
4.3 TimesheetNumber Auto-increment
Change introduced by this migration 🎯:
modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b => {
// … other properties …
b.Property<int>("TimesheetNumber")
.ValueGeneratedOnAdd() // EF Core: generate on INSERT
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("TimesheetNumber"));
b.HasKey("Id");
b.ToTable("MechanicTimesheet", "irby");
});
- Before:
TimesheetNumberwas a regular integer column. - After: It becomes an IDENTITY column (auto‑incremented).
🗄️ Domain Entities Summary
Over 120+ entities are scaffolded. Below is a short sample; full list is in the file.
| Entity Name | Table Schema.Table | Key(s) | Important Notes |
|---|---|---|---|
| Asset | irby.Asset |
Id (GUID) |
TPH base for various asset types (Computer, Monitor, …) |
| MechanicTimesheet | irby.MechanicTimesheet |
Id (GUID) |
New identity on TimesheetNumber |
| Employee | irby.Employee |
EmployeeId (GUID) |
Unique index on JdeNumber |
| Job | irby.Job |
JobId (GUID) |
Unique index on JdeNumber |
| FieldOffice | irby.FieldOffice |
Id (GUID) |
Unique index on JdeNumber |
| TimeSheetEntry | irby.TimeSheetEntry |
TimeSheetEntryId (GUID) |
FK → Employee, → TimeEntryType |
| DocumentImage | irby.DocumentImage |
DocumentImageId (GUID) |
Multi-role booleans, OCR support |
| Permissions | irby.Permissions |
PermissionId (GUID) |
Audit trail via LinkRolePermission |
| … and many more… |
🖼️ Simplified UML Class Diagram
classDiagram
class MechanicTimesheet {
+Guid Id
+String CostType
+DateTime StartDate
+int TimesheetNumber <<identity>>
}
class Asset {
+Guid Id
+string SerialNumber
+string Status
}
class Computer
class MobileDevice
Asset <|-- Computer
Asset <|-- MobileDevice
MechanicTimesheet ..|> Employee : FK_Employee
Asset --> AssetModel : FK_ModelId
AssetModel --> Manufacturer
TimeSheetEntry --> Employee
TimeSheetEntry --> TimeEntryType
Legend:
<<identity>>= Auto‑increment column- Solid arrows = inheritance
- Dashed arrows = relationships
🚀 Usage & Applying Migration
- Add migration (already created):
dotnet ef migrations add AddAutoIncrementTimesheetNumber - Update database:
dotnet ef database update - SQL Impact:
ALTER TABLE [irby].[MechanicTimesheet] ADD [TimesheetNumber] int IDENTITY(1,1) NOT NULL; - Rolling back:
dotnet ef database update <previous_migration_name>
🧪 Testing & Verification
- Smoke test: Insert new
MechanicTimesheetwithout specifyingTimesheetNumber, then confirm:var timesheet = new MechanicTimesheet { /* other properties */ }; context.MechanicTimesheets.Add(timesheet); await context.SaveChangesAsync(); Console.WriteLine(timesheet.TimesheetNumber); // should be > 0 - Schema diff:
dotnet ef migrations script --idempotent - Integration: Confirm EF queries on
TimesheetNumberwork as expected (e.g. ORDER BY).
📘 Further Reading & References
- EF Core Migrations: https://docs.microsoft.com/ef/core/managing-schemas/migrations/
- SQL Server Identity Columns: https://docs.microsoft.com/sql/t-sql/statements/create-table-identity
- EF Core Model Building: https://docs.microsoft.com/ef/core/modeling/
- TPH Inheritance Patterns: https://docs.microsoft.com/ef/core/modeling/inheritance
👍 Congratulations! You now have a detailed map of
20240724182925_AddAutoIncrementTimesheetNumber.Designer.cs. Use this as a reference for understanding your database schema evolution and ensuring consistency across environments.