đ 20250306183744_AddCrewEquipmentTable.Designer.cs Documentation
Table of Contents
- Overview & Purpose
- EF Core Migrations Context
- Designer File Structure
- Key Entity:Â CrewEquipment
- Relationship Mapping
- Model Snapshot & Annotations
- Using the Migration
- UML Diagram
- Dependencies & Technologies
- Conclusion
1. Overview & Purpose
File
IrbyImaging.DbContext/Migrations/20250306183744_AddCrewEquipmentTable.Designer.cs
Purpose
This is an autoâgenerated Entity Framework Core designer file for the migration AddCrewEquipmentTable. It contains the model snapshot (via BuildTargetModel) representing the entire database schema after applying the migration that adds the new CrewEquipment table into the irby schema.
- đ ïž Role: Captures entity mappings, keys, indexes, relationships.
- đ Scope: All domain entities up to this migration.
- âïž Benefit: Enables EF Core to diff, apply, or roll back schema changes consistently.
2. EFÂ Core Migrations Context
When you scaffold a migration with EF Core, two files are produced:
Migrations/
âââ âŠ_PreviousMigration.cs
âââ âŠ_PreviousMigration.Designer.cs â Snapshot before new changes
âââ 20250306183744_AddCrewEquipmentTable.cs â Up/Down methods
âââ 20250306183744_AddCrewEquipmentTable.Designer.cs â Model snapshot after changes
*.cs- Implements
Up()/Down()âthe DDL to modify your database.
- Implements
*.Designer.cs- Implements
BuildTargetModel(ModelBuilder)âa snapshot of your EF Core model.
- Implements
3. Designer File Structure
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace IrbyImaging.DbContext.Migrations
{
[DbContext(typeof(IrbyContext))]
[Migration("20250306183744_AddCrewEquipmentTable")]
partial class AddCrewEquipmentTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
// Global annotations
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// Configure identity columns for SQLÂ Server
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// ⊠dozens of modelBuilder.Entity(...) calls âŠ
// Our new entity mapping
modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEquipment", b => { /* ⊠*/ });
#pragma warning restore 612, 618
}
}
}
đ Key Sections
| Section | Description |
|---|---|
| Annotations | ProductVersion, MaxIdentifierLength, etc. |
| Identity Columns Setup | UseIdentityColumns for SQLÂ Server ID generation |
| Entity Mappings | Blocks of modelBuilder.Entity(...) for each class |
4. Key Entity:Â CrewEquipment
This migration adds the CrewEquipment entity: a join table linking Crew, Equipment, and Job with audit and softâdelete support.
| Property | Type | Details |
|---|---|---|
CrewEquipmentId |
Guid |
PK, generated on add |
CreatedBy |
string |
Username who created the record |
CreatedDate |
DateTime |
Timestamp of creation |
CrewId |
Guid |
FK â Crew table |
EquipmentId |
Guid |
FK â Equipment table |
JobId |
Guid |
FK â Job table |
IsDeleted |
bool |
Softâdelete flag (logical deletion) |
Mapping Snippet
modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEquipment", b =>
{
b.ToTable("CrewEquipment", "irby");
b.Property<Guid>("CrewEquipmentId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CreatedBy")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("CreatedDate")
.HasColumnType("datetime2");
b.Property<Guid>("CrewId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("EquipmentId")
.HasColumnType("uniqueidentifier");
b.Property<Guid>("JobId")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
// Primary Key
b.HasKey("CrewEquipmentId");
// Indexes for foreign keys
b.HasIndex("CrewId");
b.HasIndex("EquipmentId");
b.HasIndex("JobId");
});
5. Relationship Mapping
modelBuilder.Entity("IrbyImaging.DomainClasses.CrewEquipment", b =>
{
// One Crew â Many CrewEquipment
b.HasOne("IrbyImaging.DomainClasses.Crew", "Crew")
.WithMany("CrewEquipment")
.HasForeignKey("CrewId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
// One Equipment â Many CrewEquipment
b.HasOne("IrbyImaging.DomainClasses.Equipment", "Equipment")
.WithMany()
.HasForeignKey("EquipmentId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
// One Job â Many CrewEquipment
b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
.WithMany()
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
- đȘąÂ Crew â CrewEquipment â Equipment
- đȘąÂ CrewEquipment â Job
6. Model Snapshot & Annotations
At the top of BuildTargetModel, youâll see global annotations:
modelBuilder
.HasAnnotation("ProductVersion", "9.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
- ProductVersion: EFÂ Core 9.0.0
- MaxIdentifierLength: 128 (SQL Server default)
- UseIdentityColumns: Enables
IDENTITYon key columns
7. Using the Migration
- Add Migration
dotnet ef migrations add AddCrewEquipmentTable - Apply to Database
dotnet ef database update - Verify
- Confirm presence of
irby.CrewEquipmenttable - Inspect foreign keys and indexes
- Confirm presence of
8. UML Diagram
erDiagram
CREW ||--o{ CREW_EQUIPMENT : has
EQUIPMENT ||--o{ CREW_EQUIPMENT : uses
JOB ||--o{ CREW_EQUIPMENT : assigned_to
CREW {
Guid CrewId PK
string CrewName
...
}
EQUIPMENT {
Guid EquipmentId PK
string DisplayName
...
}
JOB {
Guid JobId PK
string Name
...
}
CREW_EQUIPMENT {
Guid CrewEquipmentId PK
Guid CrewId FK
Guid EquipmentId FK
Guid JobId FK
DateTime CreatedDate
bool IsDeleted
}
9. Dependencies & Technologies
| Technology | Version |
|---|---|
| .NET SDK | â„ 7.0 |
| EF Core | 9.0.0 |
| SQL Server Engine | 2016+ |
| C# Language | 10.0+ |
10. Conclusion
This Designer file is the EFÂ Core snapshot after applying the AddCrewEquipmentTable migration. It ensures that EFÂ Core knows precisely how to build or rebuild your database schema at this point in timeâcomplete with entity definitions, foreign keys, indexes, and global annotations. đ