📐 UpdateMechanicTimesheet Migration Designer
File:
IrbyImaging.DbContext/Migrations/20240701202611_UpdateMechanicTimesheet.Designer.cs
Namespace:IrbyImaging.DbContext.Migrations
Migration:20240701202611_UpdateMechanicTimesheet
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models
- BuildTargetModel Method
- UML Diagram
- Usage Examples
- Adding & Applying Migrations
- Conclusion
🧐 Overview & Purpose
The UpdateMechanicTimesheet.Designer.cs file is an auto-generated Entity Framework Core migration designer. It captures the state of your EF Core model after applying the UpdateMechanicTimesheet migration.
- Why it exists: EF Core uses it to know how to build the database schema (tables, columns, keys, relationships) when you run
Update-Database. - What it does: Implements
BuildTargetModel(ModelBuilder modelBuilder)which configures the entire set of domain entities—including the newly updated MechanicTimesheet table.
⚙️ Dependencies & Technologies
| Technology | Version / Usage |
|---|---|
| .NET SDK | 7.0.x |
| C# | 10+ |
| Entity Framework Core | 7.0.7 (with SQL Server provider) |
| EF Core Migrations | Code-based migrations (Designer + Up/Down) |
| Microsoft.EntityFrameworkCore.SqlServer | For .UseIdentityColumns() extension |
🔑 Key Functional Areas
-
Migration Attributes
[DbContext(typeof(IrbyContext))][Migration("20240701202611_UpdateMechanicTimesheet")]
-
Model Annotations
- Specifies ProductVersion (
7.0.7) - Configures Relational:MaxIdentifierLength (128)
- Enables Identity Columns for SQL Server
- Specifies ProductVersion (
-
Global Entity Configuration
- Table names, schemas (
"irby"), primary keys, indexes - Discriminator-based configuration for TPH inheritance
- Table names, schemas (
-
MechanicTimesheet Update
- Adds/changes the MechanicTimesheet entity definition in the model
🗄️ Data Models
MechanicTimesheet Entity
This entity represents time entries that mechanics submit for work orders, units, and jobs.
| Property | CLR Type | Column Type | Nullable | Notes |
|---|---|---|---|---|
| Id | Guid |
uniqueidentifier |
No | PK, ValueGeneratedOnAdd() |
| EmployeeId | Guid |
uniqueidentifier |
No | FK to Employee |
| EmployeeName | string |
nvarchar(max) |
Yes | Mechanic’s display name |
| Job | string |
nvarchar(max) |
Yes | Job name or number |
| WorkOrder | string |
nvarchar(max) |
Yes | Work order identifier |
| UnitNumber | string |
nvarchar(max) |
Yes | Unit or vehicle tag |
| CostType | string |
nvarchar(max) |
Yes | Billing cost category |
| PayCode | string |
nvarchar(max) |
Yes | Payroll code (e.g., regular/overtime) |
| Description | string |
nvarchar(max) |
Yes | Work description/notes |
| StartDate | DateTime |
datetime2 |
No | Date when work started |
| StartTime | string |
nvarchar(max) |
Yes | Clock‐in time |
| EndTime | string |
nvarchar(max) |
Yes | Clock‐out time |
| RegularTime | string |
nvarchar(max) |
Yes | Regular hours worked |
| OverTime | string |
nvarchar(max) |
Yes | Overtime hours |
| Status | int |
int |
No | Entry status (e.g., Pending, Approved) |
| SubmittedBy | string |
nvarchar(max) |
Yes | User who submitted the timesheet |
modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b =>
{
b.ToTable("MechanicTimesheet", "irby");
b.HasKey("Id");
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid>("EmployeeId")
.HasColumnType("uniqueidentifier");
b.Property<string>("EmployeeName")
.HasColumnType("nvarchar(max)");
// ... other properties ...
});
🔨 BuildTargetModel Method
The heart of this designer file is:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// … many Entity <> configurations …
modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b =>
{
b.ToTable("MechanicTimesheet", "irby");
// columns, keys…
});
// … relationships, navigation properties …
}
- Purpose: Describes how EF Core should generate the database schema.
- Scope: Contains all entities within
IrbyContextas of this migration. - EF API Usage:
.Entity(...)— configure each .NET class.Property(...)— define column mapping.HasKey(...),.HasIndex(...),.HasOne(...).WithMany(...)— PKs, indexes, relationships.ToTable(...)— physical table name + schema
🏷️ UML Diagram
Below is a simplified PlantUML for the MechanicTimesheet entity:
@startuml
class MechanicTimesheet {
+ Guid Id
+ Guid EmployeeId
+ string EmployeeName
+ string Job
+ string WorkOrder
+ string UnitNumber
+ DateTime StartDate
+ string StartTime
+ string EndTime
+ string RegularTime
+ string OverTime
+ int Status
+ string SubmittedBy
}
MechanicTimesheet --> "1" Employee : FK
@enduml
📝 Usage Examples
-
Inspect the generated model
OpenUpdateMechanicTimesheet.Designer.csto see how MechanicTimesheet (and other entities) are configured. -
Apply the migration
# From Package Manager Console Update-Database 20240701202611_UpdateMechanicTimesheetOr
# Using dotnet CLI dotnet ef database update 20240701202611_UpdateMechanicTimesheet -
Query in your code
using (var ctx = new IrbyContext()) { var entries = ctx.Set<MechanicTimesheet>() .Where(e => e.EmployeeId == someGuid) .ToList(); // … }
🚀 Adding & Applying Migrations
- Create a new migration after changing your domain classes:
dotnet ef migrations add UpdateMechanicTimesheet - This generates:
20240701202611_UpdateMechanicTimesheet.cs(Up/Down logic)20240701202611_UpdateMechanicTimesheet.Designer.cs(model snapshot)
- Apply to target database:
dotnet ef database update
🏁 Conclusion
The UpdateMechanicTimesheet.Designer.cs file is a snapshot of your entire EF Core model at the time you created the UpdateMechanicTimesheet migration. It serves as the blueprint for how Entity Framework will scaffold tables, columns, keys, and relationships in your irby schema—especially ensuring the MechanicTimesheet table is up-to-date with your domain class.
Keep this file under source control alongside its accompanying Up()/Down() migration to maintain a reliable, versioned history of your database schema.
Happy coding! 🛠️