📑 Documentation: RemoveFKInWOTable.Designer.cs
Filepath:
IrbyImaging.DbContext/Migrations/20240307125423_RemoveFKInWOTable.Designer.cs
Namespace:IrbyImaging.DbContext.Migrations
Auto‑Generated: Yes
EF Core Version: 7.0.7
🗂️ Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Metadata 🏷️
- BuildTargetModel Method 🏗️
- Key Entity Spotlight
- 5.1 WorkOrder Table 🎯
- 5.2 Asset Hierarchy 📋
- Indexes & Constraints 🛠️
- Using EF Core Migrations
- Sample Snippets 💻
- UML Diagram Example 🏛️
- Conclusion 📜
1. Overview & Purpose
This auto‑generated designer file is part of the EF Core migrations infrastructure.
It defines the target model snapshot for the migration 20240307125423_RemoveFKInWOTable, which—by its name—removes a foreign key constraint from the WorkOrder table.
- BuildTargetModel: Captures the final shape of your database schema
- Migration Class: Holds metadata so EF Core can compute schema diffs
🔎 Why it matters
- Ensures Up/Down scripts apply reliably
- Tracks entity updates (columns, keys, relationships)
- Do not manually edit: regenerate via
dotnet ef migrations add
2. Dependencies & Technologies
| Technology | Version | Purpose |
|---|---|---|
| .NET / C# | 7.0.7 | Runtime & language |
| Entity Framework Core | 7.0.7 | ORM & Migrations |
| SQL Server | (Relational) | Target database provider |
| ModelBuilder API | — | Fluent configuration of tables & relations |
3. Migration Metadata 🏷️
[DbContext(typeof(IrbyContext))]
[Migration("20240307125423_RemoveFKInWOTable")]
partial class RemoveFKInWOTable
{
// ...
}
- DbContext Attribute
Associates this migration withIrbyContext. - Migration Attribute
Unique timestamp-based identifier:
20240307125423_RemoveFKInWOTable
4. BuildTargetModel Method 🏗️
This core method configures the EF Core model as it should appear after applying the migration.
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// Entity configurations follow...
// ...
#pragma warning restore 612, 618
}
4.1 Annotations & Identity Columns
- ProductVersion: Records the EF Core version
- MaxIdentifierLength: SQL Server limit (128)
- UseIdentityColumns: Sets up SQL Server IDENTITY defaults
4.2 Entity Configuration 📦
Each modelBuilder.Entity("Namespace.Class", b => { ... }) call:
- Properties (
b.Property<type>("ColumnName")) - Keys (
b.HasKey("PrimaryKeyProperty")) - Indexes (
b.HasIndex("ForeignKeyProperty")) - Table Mapping (
b.ToTable("TableName", "schema")) - Discriminator (for TPH inheritance)
Tip: The designer file lists all domain classes—no code-first classes are omitted.
4.3 Relationships & Navigations 🔗
After property definitions, EF Core scaffolds relationships:
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b => {
// ...
b.HasOne("IrbyImaging.DomainClasses.Job", "Job")
.WithMany()
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
.WithMany()
.HasForeignKey("ProjectManagerId");
b.Navigation("Job");
b.Navigation("Employee");
});
- HasOne…WithMany: Defines 1→∞
- HasForeignKey: Sets FK column
- OnDelete: Cascade, Restrict, etc.
- Navigation: Exposes CLR nav properties
5. Key Entity Spotlight
5.1 WorkOrder Table 🎯
| Column | Type | Notes |
|---|---|---|
| WorkOrderId (PK) | uniqueidentifier | IDENTITY on add |
| DateAssigned | datetime2? | Nullable |
| DateStart | datetime2? | |
| JobId (FK) | uniqueidentifier | ▶ Job (Cascade on delete) |
| ProjectManagerId (FK) | uniqueidentifier? | ▶ Employee (nullable relationship) |
| EstimatedHours | decimal(18,2) | |
| EstimatedAmount | decimal(18,2) | |
| WorkOrderNumber | nvarchar(max) | |
| Status | nvarchar(max) |
❗ Migration Concern: This designer represents the model after the foreign key removal (or alteration). Please inspect the corresponding
RemoveFKInWOTable.csfor the actual Up/Down logic.
5.2 Asset Hierarchy 📋
The Asset table uses TPH inheritance (Discriminator column):
| Discriminator Value | CLR Type | Extra Columns |
|---|---|---|
| Asset | IrbyImaging.DomainClasses.Asset | (base: SerialNumber, Status, …) |
| Computer | Asset → Computer | AssetNumber, CpsNumber, OperatingSystemId |
| MobileDevice | Asset → MobileDevice | Imei (unique), Carrier, Type, … |
| DeskPhone | Asset → DeskPhone | MacAddress, PhoneNumber |
| Monitor, Dock, Printer, OfficePrinter, SafetyEquipment | Asset subtypes | … |
6. Indexes & Constraints 🛠️
- Unique Index on
Employee.JdeNumberFieldOffice.JdeNumberJob.JdeNumberMobileDevice.Imei
- Foreign‑Key Indexes
Created automatically for each relationship.
| Entity | Indexed Columns |
|---|---|
| Asset | FieldOfficeId, ModelId, OwnerId |
| WorkOrder | JobId, ProjectManagerId |
| … | … |
7. Using EF Core Migrations
- Add a Migration
dotnet ef migrations add RemoveFKInWOTable - Apply to Database
dotnet ef database update - Inspect Designer Snapshot
- Located under
/Migrations/*.Designer.cs - Reflects after state of schema
- Located under
🚧 Note: Never edit designer files manually—always regenerate.
8. Sample Snippets 💻
Defining a New Property
modelBuilder.Entity("IrbyImaging.DomainClasses.WorkOrder", b =>
{
b.Property<string>("Reference")
.HasColumnType("nvarchar(max)");
});
Removing a Foreign Key (Up/Down logic in migration)
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_WorkOrder_Employee_ProjectManagerId",
schema: "irby",
table: "WorkOrder");
migrationBuilder.DropIndex(
name: "IX_WorkOrder_ProjectManagerId",
schema: "irby",
table: "WorkOrder");
// ...other alterations...
}
9. UML Diagram Example 🏛️
classDiagram
class WorkOrder {
+Guid WorkOrderId
+DateTime? DateAssigned
+decimal EstimatedHours
+decimal EstimatedAmount
+string WorkOrderNumber
+string Status
}
class Job {
+Guid JobId
+string Name
+string JdeNumber
}
class Employee {
+Guid EmployeeId
+string FirstName
+string LastName
+string Status
}
WorkOrder --> Job : JobId
WorkOrder --> Employee : ProjectManagerId
👉 Tip: Use Mermaid.js to render these diagrams in Markdown.
10. Conclusion 📜
The RemoveFKInWOTable.Designer.cs file is a snapshot of your EF Core model state following the RemoveFKInWOTable migration. Understanding its structure helps you:
- Audit schema evolution
- Troubleshoot relationship issues
- Ensure your domain classes map correctly
🎉 Happy coding with EF Core!
⚠️ Remember: Designer files are auto‑generated—keep your domain models and migrations in sync.