📑 Documentation: 20240917133401_AddColumnsTimesheet.Designer.cs
Path:
IrbyImaging.DbContext/Migrations/20240917133401_AddColumnsTimesheet.Designer.cs
Purpose: Auto‑generated EF Core migration snapshot capturing the “AddColumnsTimesheet” model state.
📖 Table of Contents
- Overview & Purpose
- EF Core Migrations & Designer Files
- The
BuildTargetModelMethod - Key Entities Affected
- Model Configuration Snapshot
- Working with This Migration
- Dependencies & Technologies
- Usage Examples
- Conclusion
🔍 Overview & Purpose
This Designer file is an EF Core artifact automatically generated when you run:
dotnet ef migrations add AddColumnsTimesheet
It exists to:
- 🎯 Snapshot the shape of your entire EF model after adding new timesheet columns.
- 🔄 Ensure repeatable up/down migrations by storing the exact mapping.
- 📚 Document all entities, properties, keys, indexes, and relationships at this point in time.
🛠️ EF Core Migrations & Designer Files
When you create a migration:
- Up/Down methods appear in
*.cs(e.g., adding/dropping columns). - A Designer file (this one) records a full Model snapshot via
BuildTargetModel. - During
database update, EF compares the snapshot to the database and emits SQL.
Important: You normally do not edit the Designer file by hand—it’s regenerated each time.
🔧 The BuildTargetModel Method
At its core, the Designer contains:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// Global annotations
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// Entity configurations...
modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b => { /* … */ });
modelBuilder.Entity("IrbyImaging.DomainClasses.TimeSheetEntry", b => { /* … */ });
// …plus dozens of other domain classes…
}
HasAnnotation: Captures EF Core version & SQL Server defaults.UseIdentityColumns: Sets up defaultIDENTITYfor integer PKs.modelBuilder.Entity(...): Maps each CLR Entity to a Table with Properties, Keys, Indexes, Relationships.
🗂️ Key Entities Affected
Although the snapshot covers all domain classes, this migration’s focus is on Timesheet tables:
| Entity | Table | Schema | Primary Key |
|---|---|---|---|
| MechanicTimesheet | MechanicTimesheet |
irby |
Id (GUID) |
| TimeSheetEntry | TimeSheetEntry |
irby |
TimeSheetEntryId (GUID) |
MechanicTimesheet 📋
Represents a single mechanic’s session on a work order.
The migration likely added one or more of these columns:
| Property | CLR Type | Notes |
|---|---|---|
| Id | Guid | PK, generated on add |
| TimesheetNumber | int | Database IDENTITY |
| EmployeeId | Guid | FK → Employee (navigation not shown) |
| EmployeeName | string | Mechanic’s name |
| StartDate | DateTime | Date part |
| StartTime | string | Clock‑in (e.g., “08:00”) |
| EndTime | string | Clock‑out (e.g., “17:00”) |
| RegularTime | string | e.g., “08:00” |
| OverTime | string | e.g., “02:00” |
| CostType | string | NEW – Type of labor cost |
| Description | string | NEW – Task description |
| ApprovedBy | string | NEW – Who approved |
| ReviewedBy | string | Who reviewed the timesheet |
| RejectionComment | string | Reason if status = Rejected |
| Status | int | Enum (0=New, 1=Pending, 2=Approved…) |
| SubmittedBy | string | Who submitted? |
| IsDeleted | bool | Soft‑delete flag |
Bold = likely new columns introduced by this migration.
TimeSheetEntry 📝
Captures individual time entries (for payroll or reporting).
| Property | CLR Type | Notes |
|---|---|---|
| TimeSheetEntryId | Guid | PK |
| EmployeeId | Guid | FK → Employee |
| TimeEntryTypeId | Guid | FK → TimeEntryType |
| DateWorked | Date | Date only |
| HoursWorked | decimal(18,2) | Hours logged |
| Notes | string | Optional comments |
| AddedBy | string | Created by |
| AddedDate | DateTime | Created timestamp |
| ModifiedBy | string | Last modified by |
| ModifiedDate | DateTime | Last modified time |
| IsDeleted | bool | Soft‑delete |
📊 Model Configuration Snapshot
Below is an excerpt showing how EF Core maps MechanicTimesheet:
modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<int>("TimesheetNumber")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(
b.Property<int>("TimesheetNumber"));
b.Property<Guid>("EmployeeId").HasColumnType("uniqueidentifier");
b.Property<string>("EmployeeName").HasColumnType("nvarchar(max)");
b.Property<DateTime>("StartDate").HasColumnType("datetime2");
b.Property<string>("StartTime").HasColumnType("nvarchar(max)");
b.Property<string>("EndTime").HasColumnType("nvarchar(max)");
b.Property<string>("RegularTime").HasColumnType("nvarchar(max)");
b.Property<string>("OverTime").HasColumnType("nvarchar(max)");
b.Property<string>("Job").HasColumnType("nvarchar(max)");
b.Property<string>("WorkOrder").HasColumnType("nvarchar(max)");
b.Property<string>("WorkOrderType").HasColumnType("nvarchar(max)");
b.Property<string>("PayCode").HasColumnType("nvarchar(max)");
b.Property<string>("CostType").HasColumnType("nvarchar(max)");
b.Property<string>("Description").HasColumnType("nvarchar(max)");
b.Property<string>("ApprovedBy").HasColumnType("nvarchar(max)");
b.Property<string>("ReviewedBy").HasColumnType("nvarchar(max)");
b.Property<string>("RejectionComment").HasColumnType("nvarchar(max)");
b.Property<int>("Status").HasColumnType("int");
b.Property<string>("SubmittedBy").HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted").HasColumnType("bit");
b.HasKey("Id");
b.ToTable("MechanicTimesheet", "irby");
});
And for TimeSheetEntry:
modelBuilder.Entity("IrbyImaging.DomainClasses.TimeSheetEntry", b =>
{
b.Property<Guid>("TimeSheetEntryId").HasColumnType("uniqueidentifier");
b.Property<Guid>("EmployeeId").HasColumnType("uniqueidentifier");
b.Property<Guid>("TimeEntryTypeId").HasColumnType("uniqueidentifier");
b.Property<DateTime>("DateWorked")
.HasColumnType("Date");
b.Property<decimal>("HoursWorked")
.HasColumnType("decimal(18,2)");
b.Property<string>("Notes").HasColumnType("nvarchar(max)");
b.Property<string>("AddedBy").HasColumnType("nvarchar(max)");
b.Property<DateTime>("AddedDate").HasColumnType("datetime2");
b.Property<string>("ModifiedBy").HasColumnType("nvarchar(max)");
b.Property<DateTime>("ModifiedDate").HasColumnType("datetime2");
b.Property<bool>("IsDeleted").HasColumnType("bit");
b.HasKey("TimeSheetEntryId");
b.HasIndex("EmployeeId");
b.HasIndex("TimeEntryTypeId");
b.ToTable("TimeSheetEntry", "irby");
});
🔄 Working with This Migration
- Add columns (in your C# model classes).
- Generate the migration:
dotnet ef migrations add AddColumnsTimesheet - Apply to database:
dotnet ef database update - Verify that new columns exist in
MechanicTimesheetandTimeSheetEntrytables.
📦 Dependencies & Technologies
- .NET 7.0.7
- EntityFrameworkCore 7 (Microsoft.EntityFrameworkCore & Microsoft.EntityFrameworkCore.SqlServer)
- C# 10
This file lives alongside your other migrations under the Migrations folder.
✨ Usage Examples
# Create the migration
dotnet ef migrations add AddColumnsTimesheet
# Migration code appears in:
# ├─ …/AddColumnsTimesheet.cs
# └─ …/AddColumnsTimesheet.Designer.cs
# Apply to your dev database
dotnet ef database update
# Inspect SQL script
dotnet ef migrations script AddColumnsTimesheet
📈 Conclusion
This Designer snapshot ensures your AddColumnsTimesheet migration is repeatable, transparent, and safely applied. It records every entity configuration (not just timesheet tables) so you can roll forward or back without drift.
Keep your C# model classes in sync, let EF Core manage the migrations, and rely on this snapshot to track your schema evolution!
Happy coding! 🚀