📑 Migration: AddTimesheetNumber (20250303151248)
File: IrbyImaging.DbContext/Migrations/20250303151248_AddTimesheetNumber.Designer.cs
Generated On: 2025-03-03T15:12:48
🗂 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Class Structure
- BuildTargetModel Method
- Data Model Change: FieldTimesheet
- UML Diagram
- Usage Example
- Conclusion
1. Overview & Purpose
This auto‑generated designer file represents the Entity Framework Core snapshot of your model at the point of the AddTimesheetNumber migration. Its primary role is to:
- Capture the complete shape of your EF model (all entities, properties, relationships)
- Reflect the introduction of an identity column
TimesheetNumberon theFieldTimesheettable - Enable EF Core to compute diffs and apply further migrations correctly
“Migrations snapshots” like this ensure consistency between future code changes and the database schema.
2. Dependencies & Technologies
| Technology / Package | Version | Purpose |
|---|---|---|
| Microsoft.EntityFrameworkCore | 9.0.0 | Core ORM, model building & migrations |
| Microsoft.EntityFrameworkCore.Relational | 9.0.0 | Relational database extensions (SQL Server) |
| Microsoft.EntityFrameworkCore.SqlServer | 9.0.0 | SQL Server provider |
| Microsoft.EntityFrameworkCore.Design | 9.0.0 | Migrations and tooling support |
3. Migration Class Structure
[DbContext(typeof(IrbyContext))]
[Migration("20250303151248_AddTimesheetNumber")]
partial class AddTimesheetNumber
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// ... entity configurations ...
}
}
-
Attributes
[DbContext(typeof(IrbyContext))]ties this snapshot to your customIrbyContext.[Migration("…")]identifies the unique timestamped migration.
-
Partial Class allows you to extend it (if absolutely needed) without modifying the generated code.
4. BuildTargetModel Method
This method reconstructs the entire EF Core model. Key steps include:
-
Global Annotations
modelBuilder .HasAnnotation("ProductVersion", "9.0.0") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);- Sets EF Core version & SQL Server max identifier length.
- Enables Identity columns by default.
-
Entity Configurations
- All domain entities (
AccountBalances,Job,Employee,FieldTimesheet, etc.) are described here. - Each
.Entity("…", b => { … })block configures properties, keys, indexes, relationships, and table mappings.
- All domain entities (
-
Relationships & Navigations
- After properties, the snapshot wires up foreign‑key constraints and
.Navigation(...)calls.
- After properties, the snapshot wires up foreign‑key constraints and
5. Data Model Change: FieldTimesheet
The sole substantive change introduced by this migration is the addition of the identity column TimesheetNumber on the FieldTimesheet entity.
| Property | Type | Configuration |
|---|---|---|
TimesheetId |
Guid | Primary key |
TimesheetNumber |
int | Identity/auto-increment (ValueGeneratedOnAdd()) |
modelBuilder.Entity("IrbyImaging.DomainClasses.FieldTimesheet", b =>
{
b.Property<Guid>("TimesheetId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// 💡 Newly added identity column
b.Property<int>("TimesheetNumber")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(
b.Property<int>("TimesheetNumber")
);
// other properties …
b.HasKey("TimesheetId");
b.ToTable("FieldTimesheet", "irby");
});
- Why?
- Prior to this, timesheets were only uniquely identified by a GUID (
TimesheetId). - The new
TimesheetNumberprovides a human‑friendly, sequential integer for reporting/lookup.
- Prior to this, timesheets were only uniquely identified by a GUID (
6. UML Diagram
@startuml
entity "FieldTimesheet (irby)" {
* TimesheetId : Guid <<PK>>
* TimesheetNumber : int <<Identity>>
--
ApprovedBy : string
ApprovedDate : DateTime
CreatedDate : DateTime
// … other props …
}
@enduml
Figure: Conceptual shape of the
FieldTimesheettable after this migration.
7. Usage Example
- Create Migration
dotnet ef migrations add AddTimesheetNumber - Apply to Database
dotnet ef database update - Verify
SELECT TimesheetNumber, * FROM irby.FieldTimesheet ORDER BY TimesheetNumber DESC;
8. Conclusion
👍 This designer snapshot is critical for ensuring your EF Core model remains in sync with your database schema across migrations. The addition of TimesheetNumber as an identity column:
- Improves readability & reporting
- Eases integration with legacy systems requiring numeric identifiers
- Retains GUID PK for internal uniqueness
Next Steps: Review your application code where you insert or read timesheets—to leverage the new
TimesheetNumber(e.g., display on UI, include in logs or audit trails).
Generated by EF Core – keep this file under source control, do not manually edit! 🚀