📦 Migration: 20230201064404_LyTxTableAddColumn.Designer.cs
Auto-generated Entity Framework Core migration snapshot for the “LyTxTableAddColumn” migration.
This file describes the target database model after applying the migration.
📑 Table of Contents
- Overview & Purpose
- Key Components
- Entities & Table Mappings
- How to Apply This Migration
- Dependencies & Technologies
- Appendix: Sample EF CLI Commands
- Conclusion
🧐 Overview & Purpose
Entity Framework Core uses migrations to evolve your database schema alongside your code.
This file is the designer snapshot for migration 20230201064404_LyTxTableAddColumn, automatically generated under:
IrbyImaging.DbContext/Migrations/20230201064404_LyTxTableAddColumn.Designer.cs
- It captures the final model (all tables, columns, indexes, relationships) that EF expects after the migration runs.
- Paired with the corresponding
*.csmigration file (withUp()/Down()methods), it allows EF to compare your code model vs. the database and generate diffs.
⚙️ Key Components
1. Migration Attributes
[DbContext(typeof(IrbyContext))]
[Migration("20230201064404_LyTxTableAddColumn")]
partial class LyTxTableAddColumn { … }
- DbContext attribute binds this migration to your
IrbyContext. - Migration attribute gives a timestamped identifier (
20230201064404) plus a descriptive name (LyTxTableAddColumn).
2. BuildTargetModel Method
The heart of the designer file:
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.12")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// … entity mappings follow …
}
-
Annotations
MaxIdentifierLength: Maximum length for SQL identifiers.ProductVersion: EF Core version that generated this snapshot.SqlServer:ValueGenerationStrategy: Default key-generation for SQL Server.
-
Entity Definitions
Each call tomodelBuilder.Entity("Namespace.ClassName", b => { … })defines:- Properties → Columns (type, nullability, default values).
- Keys → Primary and alternate keys.
- Indexes → Indexes and unique constraints.
- Table mapping → Schema and table name (e.g.,
"irby.Asset"). - Relationships →
HasOne()…WithMany()…HasForeignKey().
📊 Entities & Table Mappings
Below is a high-level summary of some core entities added or updated by this migration:
Entity (Class) |
Table (Schema.Name) |
PK / Key Columns | Notes / Relationships |
|---|---|---|---|
| Asset | irby.Asset | Id (GUID) |
Inheritance Discriminator; FK: ModelId, OwnerId, FieldOfficeId |
| AssetHistory | irby.AssetHistory | Id (GUID) |
Tracks changes to assets |
| AssetModel | irby.AssetModel | Id (int) |
FK: MakeId → Manufacturer |
| AssetModelDetail | AssetModelDetail | Id (int) |
Optional detail record |
| LytxTemplate ✨ | irby.LytxTemplate | Id (GUID) |
New or modified record for Lytx batch processing |
| Employee | irby.Employee | Id (GUID) |
Unique on JdeNumber; FK → Job |
| FieldOffice | irby.FieldOffice | Id (GUID) |
FK → Manager, ProjectManager, Superintendent |
| Ticket | irby.Ticket | Id (GUID) |
Customer support / request tickets |
| Update | irby.Update | Id (GUID) |
FK → Ticket; tracks status changes |
Note: The snapshot includes 50+ entities, covering assets, documents, invoices, ODS staging tables, etc.
For brevity, we show a selection above.
🎨 Mermaid Diagram (Partial)
classDiagram
Asset <|-- Computer
Asset <|-- MobileDevice
Asset o-- AssetModel : Model
AssetModel -- Manufacturer : Make
Employee "1" o-- "*" Asset : Owner
Ticket "1" o-- "*" Update
FieldOffice "1" o-- "*" Asset
🚀 How to Apply This Migration
-
Add Migration
(Already done – creates this snapshot + Up()/Down() code.)dotnet ef migrations add 20230201064404_LyTxTableAddColumn \ --context IrbyContext -
Update Database
Applies pending migrations (including this one) to your SQL Server database:dotnet ef database update \ --context IrbyContext
🔧 Dependencies & Technologies
- .NET 5.0 (
ProductVersion: 5.0.12) - EntityFrameworkCore & SqlServer provider
- C# 9.0, leveraging EF Core’s Fluent‑API for model building
📋 Appendix: Sample EF CLI Commands
| Purpose | Command |
|---|---|
| List Migrations | dotnet ef migrations list --context IrbyContext |
| Scaffold New Migration | dotnet ef migrations add MyMigrationName --context IrbyContext |
| Apply Migrations to DB | dotnet ef database update --context IrbyContext |
| Revert Last Migration | dotnet ef database update PreviousMigrationName --context IrbyContext |
✅ Conclusion
This Designer file is a read-only, auto-generated snapshot of your EF Core model after the LyTxTableAddColumn migration. It ensures that EF can accurately compute schema differences in future migrations.
Keep your migration Up/Down logic in the paired *.cs file, and let this designer file simply reflect your model’s shape. 🎉
Happy Coding! 🚀