📘 Documentation:
IrbyImaging.DbContext/Migrations/20230201043118_LytxTemplateNewColumnsAndVehicleTable.Designer.cs
🗂️ Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- EF Core Migration Primer 🛠️
- Data Models & Schema Changes
- Relationships & Navigation Properties
- UML Entity‑Relationship Diagram 🖼️
- How to Apply & Use This Migration 🚀
- Sample Code & Usage Examples 💻
- Conclusion 🎯
1. Overview & Purpose
This auto-generated designer file is part of an Entity Framework Core migration named
20230201043118_LytxTemplateNewColumnsAndVehicleTable. Its primary goals are:
- 🔧 Snapshot the target model (table/column definitions, relationships, indexes)
- 🚗 Introduce a new
Vehicletable into theirbyschema - ✏️ Add new columns to the existing
LytxTemplateentity - 📦 Ensure the EF Core tooling can compare the current model vs. the database
Note: You should never manually edit this file. Use EF Core commands (
Add-Migration,Update-Database) to keep it in sync.
2. Dependencies & Technologies
| Technology | Version / Usage |
|---|---|
| .NET | .NET 5.0 (C# 9) |
| Entity Framework Core | 5.0.12 |
| EF Core Migrations | Microsoft.EntityFrameworkCore.Migrations |
| Database Provider | Microsoft.EntityFrameworkCore.SqlServer |
| Value Conversions | Microsoft.EntityFrameworkCore.Storage.ValueConversion |
3. Key Functional Areas
- BuildTargetModel: Central method that recreates your entire EF Core model
- Entity Definitions: Maps each CLR class (
DomainClasses.*) to database tables - Property Configuration: Specifies column types, lengths, nullability, keys
- Indexes & Constraints: Configures primary keys, foreign keys, unique/index filters
- Discriminator Setup: Implements table‑per‑hierarchy for
Assetsubtypes
4. EF Core Migration Primer 🛠️
- Add-Migration
Add-Migration LytxTemplateNewColumnsAndVehicleTable - BuildTargetModel
- EF scaffolds this
.Designer.csfile—describing the new snapshot
- EF scaffolds this
- Update-Database
Update-Database - Verification
- Check that
Vehicletable exists - Confirm
LytxTemplatetable has new columns
- Check that
5. Data Models & Schema Changes
This migration designer declares all entities in your model. Below we focus on the new and modified parts.
5.1 LytxTemplate Entity Changes
📑 Table: irby.LytxTemplate
This entity has been extended with new properties:
| Column Name | CLR Type | SQL Type | Nullable? | Description |
|---|---|---|---|---|
| Id | Guid |
uniqueidentifier | No | Primary key |
| DriverId | string |
nvarchar(max) | Yes | ID of the driver |
| FirstName | string |
nvarchar(max) | Yes | Driver’s first name |
| LastName | string |
nvarchar(max) | Yes | Driver’s last name |
| ProcessingDate | DateTime |
datetime2 | No | When the record was processed |
| ShiftStart | DateTime |
datetime2 | No | Shift start timestamp |
| ShiftEnd | DateTime |
datetime2 | No | Shift end timestamp |
| VehicleId | string |
nvarchar(max) | Yes | Reference to a vehicle record (FK) |
Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.LytxTemplate", b => { b.Property<Guid>("Id") .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier"); b.Property<string>("DriverId") .HasColumnType("nvarchar(max)"); b.Property<string>("FirstName") .HasColumnType("nvarchar(max)"); b.Property<string>("LastName") .HasColumnType("nvarchar(max)"); b.Property<DateTime>("ProcessingDate") .HasColumnType("datetime2"); b.Property<DateTime>("ShiftStart") .HasColumnType("datetime2"); b.Property<DateTime>("ShiftEnd") .HasColumnType("datetime2"); b.Property<string>("VehicleId") .HasColumnType("nvarchar(max)"); b.HasKey("Id"); b.ToTable("LytxTemplate", "irby"); });
5.2 Vehicle Entity Introduction 🚗
📑 Table: irby.Vehicle
A brand-new entity representing vehicles, with only two columns so far:
| Column Name | CLR Type | SQL Type | Nullable? | Description |
|---|---|---|---|---|
| Id | Guid |
uniqueidentifier | No | Primary key |
| VehicleId | string |
nvarchar(max) | Yes | Unique vehicle code |
Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.Vehicle", b => { b.Property<Guid>("Id") .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier"); b.Property<string>("VehicleId") .HasColumnType("nvarchar(max)"); b.HasKey("Id"); b.ToTable("Vehicle", "irby"); });
6. Relationships & Navigation Properties
Although this migration only declares the model snapshot, the actual FK relationships are defined via HasOne / WithMany calls later in the designer:
- LytxTemplate → (no FKs declared here, but
VehicleIdcan be joined manually) - Other existing domain classes continue to reference each other (Assets ⇄ FieldOffice ⇄ Employee ⇄ Job, etc.)
Example:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { b.HasOne("IrbyImaging.DomainClasses.FieldOffice", "FieldOffice") .WithMany("Assets") .HasForeignKey("FieldOfficeId"); });
7. UML Entity-Relationship Diagram 🖼️
Below is a simplified UML diagram focusing on LytxTemplate and Vehicle:
@startuml
package irby {
class LytxTemplate {
+ Guid Id
+ string DriverId
+ string FirstName
+ string LastName
+ DateTime ProcessingDate
+ DateTime ShiftStart
+ DateTime ShiftEnd
+ string VehicleId
}
class Vehicle {
+ Guid Id
+ string VehicleId
}
LytxTemplate "1" -- "0..1" Vehicle : VehicleId ↔ Id
}
@enduml
You can paste the above into a PlantUML editor to render the diagram.
8. How to Apply & Use This Migration 🚀
- Ensure NuGet packages
dotnet add package Microsoft.EntityFrameworkCore.Design --version 5.0.12 dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 5.0.12 - Add the migration (if not already done)
dotnet ef migrations add LytxTemplateNewColumnsAndVehicleTable - Update the database
dotnet ef database update - Verify
- Use SSMS or
SELECT * FROM irby.Vehicle; - Inspect
irby.LytxTemplatefor the new columns
- Use SSMS or
9. Sample Code & Usage Examples 💻
9.1 Inserting a Vehicle
using (var context = new IrbyContext())
{
var vehicle = new Vehicle {
VehicleId = "TRUCK-123"
};
context.Add(vehicle);
context.SaveChanges();
}
9.2 Linking a LytxTemplate Record to Vehicle
using (var context = new IrbyContext())
{
var template = new LytxTemplate {
DriverId = "D-556",
FirstName = "Jane",
LastName = "Doe",
ProcessingDate = DateTime.UtcNow,
ShiftStart = DateTime.UtcNow.AddHours(-8),
ShiftEnd = DateTime.UtcNow,
VehicleId = context.Vehicles.First().Id.ToString()
};
context.Add(template);
context.SaveChanges();
}
10. Conclusion 🎯
This migration’s designer file provides a complete snapshot of your EF Core model at the point where:
Vehicleis introduced to track fleet unitsLytxTemplateis enhanced with driver & shift data linking to vehicles
Use this reference to understand how EF Core maps your domain classes to database tables, and to guide future schema changes.
Happy coding! 🚀
Generated by EF Core Migrations Designer – do not modify by hand.