📚 Documentation: AddApprovalDateMechanic.Designer.cs
🗂️ Table of Contents
- Introduction & Context
- EF Core Migrations Overview
- File: AddApprovalDateMechanic.Designer.cs
- How to Use This Migration
- Sample Code Snippets
- UML Diagram
- Conclusion 🎉
🎯 Introduction & Context
The AddApprovalDateMechanic.Designer.cs file is an auto‑generated EF Core migration snapshot. It lives under:
IrbyImaging.DbContext/Migrations/20250303160308_AddApprovalDateMechanic.Designer.cs
Its main job is to record the state of your entity model after applying the AddApprovalDateMechanic migration. EF Core uses this “model snapshot” when generating future migrations to detect changes.
🔧 EF Core Migrations Overview
-
Up/Down Migrations
Up(...): Applies schema changes (e.g., adds a column).Down(...): Reverts those changes.
-
Designer File
- BuildTargetModel(ModelBuilder)
- Captures the complete model configuration (tables, columns, relationships) after the migration.
- Used by EF Core to compare current model vs. next migration.
- BuildTargetModel(ModelBuilder)
-
Migration Process
dotnet ef migrations add AddApprovalDateMechanic- EF Core scaffolds
*.csand*.Designer.cs. dotnet ef database updateapplies theUpmethod.
📄 File: AddApprovalDateMechanic.Designer.cs
📝 Purpose & Role
| Item | Description |
|---|---|
| Class | AddApprovalDateMechanic (partial) |
| Attributes | [DbContext(typeof(IrbyContext))][Migration("20250303160308_AddApprovalDateMechanic")] |
| Key Method | protected override void BuildTargetModel(ModelBuilder modelBuilder) |
| Responsibility | Store the complete EF Core model state after adding the ApprovalDate column to the MechanicTimesheet table. |
⚙️ Dependencies & Technologies
- .NET 9.0.0 (per
HasAnnotation("ProductVersion","9.0.0")) - Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.MigrationsMicrosoft.EntityFrameworkCore.MetadataMicrosoft.EntityFrameworkCore.Infrastructure
- SQL Server (identity columns via
UseIdentityColumns)
🚀 Key Functional Areas
- Model Snapshot
- Re‑creates every entity mapping: tables, columns, keys, indices, relationships.
- Schema Annotations
- Database provider specifics (
UseIdentityColumns,Relational:MaxIdentifierLength).
- Database provider specifics (
- Discriminator Mapping
- Table‑per‑hierarchy for inherited types (e.g.,
Assetsubtypes:Computer,MobileDevice, etc.).
- Table‑per‑hierarchy for inherited types (e.g.,
- Navigation Relationships
- Defines
HasOne,WithMany,OnDeletebehaviors.
- Defines
🔍 BuildTargetModel Method Explained
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// Example: MechanicTimesheet entity mapping
modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// NEW COLUMN added by migration:
b.Property<DateTime>("ApprovedDate")
.HasColumnType("datetime2");
// ... other properties, keys, and table name ...
b.HasKey("Id");
b.ToTable("MechanicTimesheet","irby");
});
// ... ALL other entities ...
#pragma warning restore 612, 618
}
- Annotations: Declare EF Core version & identifier length.
UseIdentityColumns: Enables SQL Server identity (auto‑increment) for integer PKs.- Entity Blocks: For each CLR type:
b.Property<...>(...): Defines column type, nullability, defaults.b.HasKey(...): Sets the primary key.b.ToTable(...): Maps CLR type → schema.table.b.HasIndex(...): Defines DB indices.b.HasOne(...)…WithMany(...): Configures relationships.
🗃️ Snapshot of Data Models
This migration supports dozens of entities. Below is a sample list of a few tables captured:
| Entity Class | Table (Schema) | Primary Key |
|---|---|---|
MechanicTimesheet |
irby.MechanicTimesheet |
Id (GUID) |
FieldTimesheet |
irby.FieldTimesheet |
TimesheetId (GUID) |
Employee |
irby.Employee |
EmployeeId (GUID) |
Job |
irby.Job |
JobId (GUID) |
Asset + TPH Subclasses |
irby.Asset |
Id (GUID), Discriminator |
| … many more (Equipment, Invoice, WIP, etc.) |
⚙️ How to Use This Migration
- Add Migration
dotnet ef migrations add AddApprovalDateMechanic - Review Generated Files
20250303160308_AddApprovalDateMechanic.cs20250303160308_AddApprovalDateMechanic.Designer.cs
- Apply to Database
dotnet ef database update - Rollback (if needed)
dotnet ef database update [PreviousMigrationName]
💻 Sample Code Snippets
Up/Down Migration (non‑designer file)
public partial class AddApprovalDateMechanic : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "ApprovedDate",
schema: "irby",
table: "MechanicTimesheet",
type: "datetime2",
nullable: false,
defaultValue: DateTime.UtcNow // or a specific default
);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ApprovedDate",
schema: "irby",
table: "MechanicTimesheet");
}
}
Applying the Migration
# Adds & applies the migration in one go:
dotnet ef migrations add AddApprovalDateMechanic
dotnet ef database update
📊 UML Diagram
classDiagram
class AddApprovalDateMechanic {
<<Migration>>
+Up(migrationBuilder)
+Down(migrationBuilder)
-BuildTargetModel(modelBuilder)
}
class MechanicTimesheet {
Id: Guid
ApprovedDate: DateTime
// … other columns …
}
AddApprovalDateMechanic ..> MechanicTimesheet : adds ➞ ApprovedDate
MechanicTimesheet --|> Table : "irby.MechanicTimesheet"
🎉 Conclusion
The AddApprovalDateMechanic.Designer.cs file is a snapshot of your EF Core model after the AddApprovalDateMechanic migration. It ensures EF Core can correctly calculate future migrations by comparing the current model with a fresh build of your C# entity classes.
- No manual edits required – it’s auto‑generated.
- Keep it under source control for consistent migrations across environments.
- Use the Up/Down methods in the corresponding
.csfile to manage your database schema.
With this setup, adding new properties to domain classes (like ApprovedDate) becomes a breeze—EF Core takes care of the SQL DDL for you! 🚀
Generated with 💙 by EF Core tooling.