📦 IrbyImaging.DbContext/Migrations/20240307190246_AddNewTablesForEquipmentReference.Designer.cs
Auto‑generated by Entity Framework Core
Context:IrbyContext
Migration:20240307190246_AddNewTablesForEquipmentReference
🧭 Table of Contents
- Overview & Purpose
- Migration Details
- New Data Models
- Entity Configurations
- Relationships & Keys
- Schema Summary
- Usage Examples
- UML Diagram
- Dependencies & Technologies
- Conclusion
1. 🌟 Overview & Purpose
This .Designer.cs file is part of the EF Core migration snapshot for the AddNewTablesForEquipmentReference migration.
It defines the target model (database schema) after applying the migration to the IrbyContext.
Key goals of this migration:
- Introduce reference tables for equipment classification:
- EquipmentClass
- EquipmentType
- Enhance the existing Equipment entity with new properties (
ClassandType) to link against these reference tables. - Provide a centralized lookup for equipment categories and types in the application.
💡 Designer files are auto‑generated and should not be edited by hand.
2. 🛠️ Migration Details
[DbContext(typeof(IrbyContext))]
[Migration("20240307190246_AddNewTablesForEquipmentReference")]
partial class AddNewTablesForEquipmentReference
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// Model definitions for all entities go here...
}
}
BuildTargetModel(...)- Configures all entities (existing + new) via the
modelBuilder. - Applies table names, schemas, keys, indexes, column types, relationships, and value conversions.
- Configures all entities (existing + new) via the
3. 🆕 New Data Models
| Entity Name | Table Name | Description |
|---|---|---|
| EquipmentClass | EquipmentClass |
Lookup table for equipment categories (e.g. Heavy, Light) |
| EquipmentType | EquipmentType |
Types of equipment within each class (e.g. Excavator, Bulldozer) |
| Equipment | irby.Equipment |
Main asset table extended with classification codes |
4. ⚙️ Entity Configurations
Below are the core snippets for each new or modified entity.
4.1 EquipmentClass
modelBuilder.Entity("IrbyImaging.DomainClasses.EquipmentClass", b =>
{
b.Property<Guid>("EquipmentClassId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<int>("ClassId")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("EquipmentClassId");
b.ToTable("EquipmentClass");
});
- 🔑 Primary Key:
EquipmentClassId(GUID) - 📦 Columns:
ClassId(int code)Name(class description)
4.2 EquipmentType
modelBuilder.Entity("IrbyImaging.DomainClasses.EquipmentType", b =>
{
b.Property<Guid>("EquipmentTypeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("EquipmentClassId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int>("TypeId")
.HasColumnType("int");
b.HasKey("EquipmentTypeId");
b.HasIndex("EquipmentClassId");
b.ToTable("EquipmentType");
});
- 🔑 Primary Key:
EquipmentTypeId(GUID) - 🔗 Foreign Key:
EquipmentClassId→EquipmentClass.EquipmentClassId - 📦 Columns:
TypeId(int code)Name(type description)
4.3 Equipment (Extended)
modelBuilder.Entity("IrbyImaging.DomainClasses.Equipment", b =>
{
b.Property<Guid>("EquipmentId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
// ... existing columns omitted for brevity ...
b.Property<int>("Class")
.HasColumnType("int"); // NEW: classification code
b.Property<int>("Type")
.HasColumnType("int"); // NEW: type code
b.HasKey("EquipmentId");
b.HasIndex("JobId");
b.ToTable("Equipment", "irby");
});
- ✔ New Properties:
Class(int)Type(int)
- These integer codes can map into
EquipmentClass.ClassId&EquipmentType.TypeIdin application logic.
5. 🔗 Relationships & Keys
| Source Entity | Navigation / FK | Target Entity | Multiplicity |
|---|---|---|---|
EquipmentType |
.HasOne(EquipmentClass) |
EquipmentClass |
* → 1 |
Equipment |
.HasOne(Job) |
Job |
* → 1 |
// EquipmentType → EquipmentClass
b.HasOne("IrbyImaging.DomainClasses.EquipmentClass", "EquipmentClass")
.WithMany()
.HasForeignKey("EquipmentClassId");
// Equipment → Job
b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
.WithMany()
.HasForeignKey("JobId");
⚠️ Note:
TheEquipmententity does not currently have direct FK relationships toEquipmentClassorEquipmentType—only integer codes (Class,Type).
Mapping between codes and reference tables is expected to be performed in business logic or via future migrations.
6. 🗒️ Schema Summary
| Table Name | Schema | Columns (key ones) | Keys & Indexes |
|---|---|---|---|
EquipmentClass |
dbo | EquipmentClassId (PK), ClassId, Name |
PK on EquipmentClassId |
EquipmentType |
dbo | EquipmentTypeId (PK), EquipmentClassId (FK), TypeId, Name |
PK on EquipmentTypeId, Index on EquipmentClassId |
Equipment |
irby | EquipmentId (PK), …, Class (int), Type (int), JobId (FK) |
PK on EquipmentId, Index on JobId |
7. 💡 Usage Examples
7.1 Applying the Migration
# Using Package Manager Console
PM> Update-Database 20240307190246_AddNewTablesForEquipmentReference
# Or via CLI
> dotnet ef database update 20240307190246_AddNewTablesForEquipmentReference
7.2 Querying Reference Data
// Retrieve all equipment classes:
var classes = dbContext.Set<EquipmentClass>()
.OrderBy(c => c.ClassId)
.ToList();
// Retrieve types for a given class:
var types = dbContext.Set<EquipmentType>()
.Where(t => t.EquipmentClassId == selectedClassId)
.OrderBy(t => t.TypeId)
.ToList();
// When creating Equipment:
var equipment = new Equipment {
Name = "Bulldozer A1",
Class = classes.First(c => c.Name=="Heavy").ClassId,
Type = types.First(t => t.Name=="Bulldozer").TypeId,
JobId = someJobId,
// ... other properties ...
};
dbContext.Add(equipment);
dbContext.SaveChanges();
8. 🕸️ UML Diagram
classDiagram
class EquipmentClass {
+Guid EquipmentClassId
+int ClassId
+string Name
}
class EquipmentType {
+Guid EquipmentTypeId
+int TypeId
+string Name
+Guid? EquipmentClassId
}
class Equipment {
+Guid EquipmentId
+int Class
+int Type
+Guid? JobId
// ... other columns omitted ...
}
EquipmentClass <|-- EquipmentType : FK
Equipment ..> Job : FK
9. 🔧 Dependencies & Technologies
- .NET 7.0
- Entity Framework Core (v7.0.7)
- Microsoft.EntityFrameworkCore.SqlServer
- Migrations: Code‑first approach
- Database: Microsoft SQL Server
10. 🎯 Conclusion
This migration establishes a robust reference for equipment classification by introducing EquipmentClass and EquipmentType tables, and by extending the existing Equipment entity with integer codes.
➡️ Benefits:
- Centralized lookup for equipment categories & types
- Strong typing & data integrity in business logic
- Simplified UI drop‑down lists for equipment selection
🔄 Future enhancements could include foreign key constraints from Equipment.Class → EquipmentClass.ClassId and Equipment.Type → EquipmentType.TypeId, or even switch to GUID‑based FKs for stronger referential integrity.
Generated on EF Core 7.0.7 — keep your migrations in sync with your domain model!