📑 Migration Documentation
File: IrbyImaging.DbContext/Migrations/20230201054443_LytxTemplateChangeDataType.Designer.cs
📋 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Anatomy
- Model Snapshot
4.1. Global Annotations
4.2. Entity Example: LytxTemplate
4.3. Other Entities (Summary) - Relationships & Navigation
- UML Diagram (Simplified)
- How EF Core Uses Designer Files
- Usage Examples
- Best Practices & Conventions
- Conclusion
1. Overview & Purpose
This auto-generated designer file is part of an Entity Framework Core (EF Core) migration named 20230201054443_LytxTemplateChangeDataType. It contains the model snapshot that EF Core uses to compare your current code-based model with the database schema.
- 🌱 Purpose:
- Captures the complete state of your EF Core model at the point in time when you added this migration.
- Enables EF Core to compute the necessary database changes when you add new migrations or roll back.
- ⚠️ Warning:
- Do not manually edit this file. Changes here are overwritten every time you scaffold a new migration.
2. Dependencies & Technologies
| Dependency | Version | Notes |
|---|---|---|
| Microsoft.EntityFrameworkCore | 5.0.12 | Core ORM library |
| Microsoft.EntityFrameworkCore.SqlServer | 5.0.12 | SQL Server provider |
| .NET SDK | 5.0.x / 6.0.x | Target framework for IrbyContext |
3. Migration Anatomy
[DbContext(typeof(IrbyContext))]
[Migration("20230201054443_LytxTemplateChangeDataType")]
partial class LytxTemplateChangeDataType
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
// ... model configuration ...
#pragma warning restore 612, 618
}
}
- [DbContext]: Associates this migration with the specific
IrbyContext. - [Migration("...")]: Unique identifier + name of the migration.
- BuildTargetModel: The heart of this file—configures every entity, property, index, constraint, and relationship.
4. Model Snapshot
4.1 Global Annotations
At the top of BuildTargetModel you’ll see model‐wide settings:
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.12")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
- MaxIdentifierLength: Maximum length for table/index names on SQL Server.
- ProductVersion: EF Core version used to scaffold.
- ValueGenerationStrategy: Default key generation strategy (Identity columns).
4.2 Entity Example: LytxTemplate 🚚
This migration’s name hints at a change in data type for the LytxTemplate entity. Below is its snapshot:
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<string>("ShiftStart")
.HasColumnType("nvarchar(max)");
b.Property<string>("ShiftEnd")
.HasColumnType("nvarchar(max)");
b.Property<string>("VehicleId")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("LytxTemplate", "irby");
});
| Column | CLR Type | SQL Type | Nullable | Notes |
|---|---|---|---|---|
| Id | Guid | uniqueidentifier | No | PK, auto-generated |
| DriverId | string | nvarchar(max) | Yes | |
| FirstName | string | nvarchar(max) | Yes | |
| LastName | string | nvarchar(max) | Yes | |
| ProcessingDate | DateTime | datetime2 | No | |
| ShiftStart | string | nvarchar(max) | Yes | |
| ShiftEnd | string | nvarchar(max) | Yes | |
| VehicleId | string | nvarchar(max) | Yes |
4.3 Other Entities (Summary)
This migration snapshot contains 30+ entities in the IrbyImaging.DomainClasses namespace, including:
- Asset, Computer, MobileDevice, Monitor (and other Asset subtypes)
- AssetModel, Manufacturer, OperatingSystem
- Employee, Job, FieldOffice, ODSEmployee, ODSJob
- DocumentType, DocumentCategory, DocumentAttribute, DocumentImage
- Ticket, Update
- BillingInvoice, GeneralLedger, GLTypeDetail
- CovidTestData, IPMMigration, TempDocumentData, IrbyForms
Each entity is configured with:
- Properties (
.Property<>()) - Keys (
.HasKey(…)) - Indexes (
.HasIndex(…)) - Table & Schema (
.ToTable("…","irby")) - Discriminator for TPH inheritance
5. Relationships & Navigation
Many-to-one and one-to-many relationships are defined via:
b.HasOne("PrincipalType", "NavigationName")
.WithMany("CollectionName")
.HasForeignKey("ForeignKeyProperty")
.OnDelete(DeleteBehavior.Cascade)
Example for
Asset→AssetModel
entity.HasOne("IrbyImaging.DomainClasses.AssetModel", "Model")
.WithMany()
.HasForeignKey("ModelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
6. UML Diagram (Simplified)
classDiagram
class LytxTemplate {
+Guid Id
+string DriverId
+string FirstName
+string LastName
+DateTime ProcessingDate
+string ShiftStart
+string ShiftEnd
+string VehicleId
}
7. How EF Core Uses Designer Files 🔄
- Comparison: EF Core compares the last applied model snapshot (this file) with your current DbContext model in code.
- Diff Generation: Determines which tables/columns/indices must be added/altered/dropped.
- Migration Scripts: Produces SQL scripts for
dotnet ef migrations addanddotnet ef database update.
8. Usage Examples
- Add a new migration (EF CLI):
dotnet ef migrations add 20230501120000_AddNewColumnToLytx --context IrbyContext - Apply pending migrations:
dotnet ef database update --context IrbyContext - Inspect the snapshot
- Open
Migrations/<timestamp>_*.Designer.csto see how EF views your model.
- Open
9. Best Practices & Conventions ✅
- Never hand-edit the
*.Designer.cssnapshot—you’ll lose changes on the next scaffold. - Keep DbContext and DomainClasses in sync: property renames, types, annotations → regenerate migrations.
- Use descriptive migration names (e.g.,
AddColumnToLytx_DateTime). - Commit both the migration
.csfile and its.Designer.cssnapshot to source control.
10. Conclusion 🎉
This designer snapshot is a critical piece of EF Core’s migrations infrastructure. It represents the complete state of the EF Core model at the moment you scaffolded 20230201054443_LytxTemplateChangeDataType. By understanding its structure, annotations, and relationships, you can more effectively manage schema evolution, troubleshoot migration issues, and ensure your database remains in sync with your domain model.
Happy coding! 🚀