🌟 Documentation: ChangeDataTypeOnODSEmployee.Designer.cs
Auto-generated by Entity Framework Core (EF Core) – part of the migration 20240222174838_ChangeDataTypeOnODSEmployee in IrbyImaging.DbContext.Migrations
📋 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Architecture & Design
- BuildTargetModel Method
4.1. High‑Level Workflow
4.2. Model Snapshot & Entities
4.3. ODSEmployee Entity Mapping
4.4. Fluent‑API Conventions & Relationships - EF Core Migrations: How It Works
- Usage & Examples
- UML Diagram
- Best Practices & Tips
- Conclusion
1. Overview & Purpose
File
IrbyImaging.DbContext/Migrations/20240222174838_ChangeDataTypeOnODSEmployee.Designer.cs
This is an auto‑generated snapshot of the EF Core model after applying the migration ChangeDataTypeOnODSEmployee. It is not meant to be edited by hand. Instead, EF Core uses it to:
- Recreate the complete database schema in memory.
- Compute diffs when you scaffold future migrations.
- Ensure consistency between your C# model and the relational schema.
2. Dependencies & Technologies
| Component | Version / Description |
|---|---|
| .NET | 7.0.7 |
| EntityFrameworkCore | Microsoft.EntityFrameworkCore 7.0.7 |
| EF Core Relational (SQL Server) | Microsoft.EntityFrameworkCore.SqlServer |
| EF Core Tools | Microsoft.EntityFrameworkCore.Tools |
| Language | C# 11 |
| Database Provider | Microsoft SQL Server (Identity Columns used) |
3. Architecture & Design
- Partial Class:
[DbContext(typeof(IrbyContext))] [Migration("20240222174838_ChangeDataTypeOnODSEmployee")] partial class ChangeDataTypeOnODSEmployee - Method:
protected override void BuildTargetModel(ModelBuilder modelBuilder) { … } - Role: Represents the target model (post‑migration) so EF can scaffold diffs.
4. BuildTargetModel Method
4.1. High‑Level Workflow
- Annotations
- Sets product version and identifier-length limits.
- Use Identity Columns
- Configures SQL Server’s identity/auto‑increment pattern.
- Entity Definitions
- For each CLR class (domain entity), calls
modelBuilder.Entity(...).
- For each CLR class (domain entity), calls
- Fluent‑API Configuration
- Properties (
.Property<>()), keys (.HasKey()), indexes, table mapping (.ToTable()), discriminators.
- Properties (
- Relationships
- Configured via
.HasOne(...).WithMany(...).HasForeignKey(...).
- Configured via
4.2. Model Snapshot & Entities
- > 70 entities under the namespace
IrbyImaging.DomainClasses - Examples include:
- Asset / Computer / MobileDevice (TPH inheritance)
- Employee, Department, Role, Permission
- FieldOffice, Job, Customer
- ODSCustomer, ODSEmployee, ODSJob (ODS = Operational Data Store)
- Ticket, Update, TimeSheetEntry, TimeEntryType
- DocumentImage, DocumentType, DocumentAttribute, etc.
All entities are mapped with column types, required rules, and relational constraints.
4.3. ODSEmployee Entity Mapping
This migration focuses on changing data types for ODSEmployee. The snapshot below shows the post‑migration mapping:
modelBuilder.Entity("IrbyImaging.DomainClasses.ODSEmployee", b =>
{
b.Property<string>("ADDRESS1")
.HasColumnType("nvarchar(max)");
b.Property<string>("CITY")
.HasColumnType("nvarchar(max)");
// … many other string/date/decimal properties …
// ← Changed property type: EMPLOYEE_ID
b.Property<byte[]>("EMPLOYEE_ID")
.HasColumnType("varbinary(max)");
// EMPLOYEE_NUMBER remains decimal
b.Property<decimal>("EMPLOYEE_NUMBER")
.HasColumnType("decimal(18,0)");
// More metadata …
b.HasKey(/* no explicit key: table may be read-only or keyless in snapshot */);
b.ToTable("ODSEmployees");
});
🔄 Summary of Key Columns
| Column | .NET Type | SQL Type | Notes |
|---|---|---|---|
| ADDRESS1, CITY, … | string |
nvarchar(max) |
Default max-length Unicode text |
| EMPLOYEE_ID | byte[] |
varbinary(max) |
Changed: storing binary GUID |
| EMPLOYEE_NUMBER | decimal |
decimal(18,0) |
Numeric with 0 decimal places |
| BIRTH_DATE, … | DateTime? |
datetime2 |
Nullable date/time |
| … | … | … | … |
Note: The actual diff (Up/Down) resides in
20240222174838_ChangeDataTypeOnODSEmployee.cs.
4.4. Fluent‑API Conventions & Relationships
- Inheritance (TPH) is used for Asset and its subtypes (
Computer,Monitor,MobileDevice, etc.):modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b => { b.HasBaseType("IrbyImaging.DomainClasses.Asset"); b.HasDiscriminator().HasValue("Computer"); // … }); - Indexes:
b.HasIndex("JdeNumber") .IsUnique() .HasFilter("[JdeNumber] IS NOT NULL"); - Foreign Keys & Navigations:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { b.HasOne("IrbyImaging.DomainClasses.FieldOffice", "FieldOffice") .WithMany("Assets") .HasForeignKey("FieldOfficeId"); // … });
5. EF Core Migrations: How It Works 🚀
- Changes in your DbContext or Entities
Add-Migration(PMC) ordotnet ef migrations add- EF Core generates TWO files:
- Migration (
Up()/Down()logic) - Designer (this file—model snapshot)
- Migration (
Update-Databaseapplies changes to the SQL database.
6. Usage & Examples 🛠
6.1. Add a Migration
dotnet ef migrations add ChangeDataTypeOnODSEmployee
6.2. Apply to Database
dotnet ef database update
6.3. Inspect Snapshot
- Open
…/Migrations/20240222174838_ChangeDataTypeOnODSEmployee.Designer.cs - Look at
BuildTargetModelfor full schema.
7. UML Diagram 📈
@startuml
package Migrations {
class ChangeDataTypeOnODSEmployee {
+ BuildTargetModel(modelBuilder)
}
}
package DomainClasses {
class ODSEmployee {
ADDRESS1: string
CITY: string
EMPLOYEE_ID: byte[]
EMPLOYEE_NUMBER: decimal
// …
}
}
Migrations.ChangeDataTypeOnODSEmployee ..> DomainClasses.ODSEmployee : snapshot
@enduml
8. Best Practices & Tips 👍
- Do not edit designer files manually—they will be overwritten.
- Keep your domain classes in sync with your migrations.
- Use descriptive migration names for clarity.
- Test migrations on a local/dev database before CI/CD deployment.
- Regularly clean up old/unused migrations to reduce complexity.
9. Conclusion
The ChangeDataTypeOnODSEmployee.Designer.cs file is a cornerstone of EF Core’s migration infrastructure. It captures the entire model state after applying the data‑type changes on ODSEmployee and dozens of other entities. By understanding its structure—especially the BuildTargetModel method—you gain insight into how EF Core translates your C# classes and fluent configuration into a concrete SQL schema.
🚀 Next Steps:
- Review the corresponding
Up()/Down()logic in the main migration file.- Run
dotnet ef migrations scriptto generate a SQL diff.- Incorporate migration testing into your CI/CD pipeline.
Happy coding! 🖥️✨