๐ Migration Designer: AddColumnsToJobTable.Designer.cs
Path:
IrbyImaging.DbContext/Migrations/20240124163357_AddColumnsToJobTable.Designer.cs
Migration:20240124163357_AddColumnsToJobTable
EF Core Version: 7.0.7 ๐
๐ Table of Contents
- ๐ Index
- ๐ง Overview & Purpose
- ๐ ๏ธ Key Functional Areas
- ๐ Dependencies & Technologies
- ๐ Data Models & Entities
- ๐ BuildTargetModel Method Explained
- ๐ Migration Workflow & Usage
- ๐ก Sample Code Snippets
- ๐ UML Diagram
- ๐ View Models & APIs
- ๐ ๏ธ Helper Methods & Utilities
- ๐ซ Error Handling & Return Types
- ๐ Thirdโparty Integrations
- ๐ Conclusion
๐ Index
| Property | Value |
|---|---|
| File Name | 20240124163357_AddColumnsToJobTable.Designer.cs |
| Class | AddColumnsToJobTable (partial) |
| DbContext | IrbyContext |
| Build Method | BuildTargetModel(ModelBuilder modelBuilder) |
| Purpose | Snapshot EF Core model for the migration |
๐ง Overview & Purpose
This auto-generated C# file is part of an Entity Framework Core migration. It:
- Captures the entire entity model (all tables, columns, relationships) as of this migration.
- Enables EF Core to diff the model when generating the SQL in the companion
Up()/Down()methods. - Ensures consistency and reproducibility of the database schema.
๐ฉ Note: You typically do not modify this file manually. It is re-generated every time you scaffold a migration.
๐ ๏ธ Key Functional Areas
- Global Annotations
- Product version, max identifier length.
- Identity Columns Configuration
.UseIdentityColumns()for SQL Server autoโincrement.
- Entity Definitions
- Properties, data types, nullability, keys, indices.
- Inheritance Mapping (TPH)
- Discriminator columns for
Assetsubclasses.
- Discriminator columns for
- Relationships & Navigation
- Foreign keys,
HasOne/WithManyassociations.
- Foreign keys,
๐ Dependencies & Technologies
| Technology | Version | Role |
|---|---|---|
| .NET SDK | 7.0.x | Runtime |
| EntityFrameworkCore.SqlServer | 7.0.7 | EF Core provider for SQL Server |
| C# / Roslyn | Latest | Language & compiler |
| SQL Server | 2016+ | Target database |
No external NuGet packages or thirdโparty APIs are referenced in this designer file.
๐ Data Models & Entities
The designer snapshots 40+ domain classes. Below are a few representative entities:
| Entity Class | Table & Schema | Description |
|---|---|---|
Asset |
irby.Asset |
Base for IT/mobile/safety equipment. |
AssetHistory |
irby.AssetHistory |
Change log for assets. |
Job |
irby.Job |
Projects/jobs. Focus of this migration. |
Employee |
irby.Employee |
Company personnel. |
FieldOffice |
irby.FieldOffice |
Office locations. |
Customer, Ticket, TimeSheetEntry, โฆ |
โฆ | Other domain tables. |
๐ฆ Focus: Job Entity & New Columns
The Job table receives one or more new/modified columns in this migration.
| Column | CLR Type | SQL Type | Notes |
|---|---|---|---|
JobId |
Guid |
uniqueidentifier |
PK, Identity-style |
FieldOfficeId |
Guid? |
uniqueidentifier |
FK โ FieldOffice.Id |
JdeNumber |
string |
nvarchar(450) |
New unique business identifier |
ManagerId |
Guid? |
uniqueidentifier |
FK โ Employee.EmployeeId |
ProjectManagerId |
Guid? |
uniqueidentifier |
FK โ Employee.EmployeeId |
SuperintendentId |
Guid? |
uniqueidentifier |
FK โ Employee.EmployeeId |
Name |
string |
nvarchar(max) |
Job name |
- ๐ Primary Key:
JobId - ๐ Indices:
- Unique on
JdeNumber(filter:IS NOT NULL) - Nonโunique on
FieldOfficeId
- Unique on
๐ BuildTargetModel Method Explained
[DbContext(typeof(IrbyContext))]
[Migration("20240124163357_AddColumnsToJobTable")]
partial class AddColumnsToJobTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// 1๏ธโฃ Global annotations
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// 2๏ธโฃ Identity column support for SQL Server
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// 3๏ธโฃ Define the Job entity
modelBuilder.Entity("IrbyImaging.DomainClasses.Job", b =>
{
b.Property<Guid>("JobId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("JdeNumber")
.HasColumnType("nvarchar(450)");
b.Property<Guid?>("FieldOfficeId")
.HasColumnType("uniqueidentifier");
// โฆ other properties โฆ
b.HasKey("JobId");
b.HasIndex("JdeNumber")
.IsUnique()
.HasFilter("[JdeNumber] IS NOT NULL");
b.HasIndex("FieldOfficeId");
b.ToTable("Job", "irby");
});
// 4๏ธโฃ Relationships & all other entitiesโฆ
}
}
- Annotations: Sets EF Core metadata.
- IdentityColumns: Enables SQL Server
IDENTITY. - Entity Config:
- Maps each CLR property โ DB column.
- Key & index definitions.
- Relationships: Configured after all entities (bottom of build).
๐ Migration Workflow & Usage
- Scaffold Migration
dotnet ef migrations add AddColumnsToJobTable - Inspect
AddColumnsToJobTable.csโ Up() / Down() methods.AddColumnsToJobTable.Designer.csโ model snapshot.
- Apply to Database
dotnet ef database update - Verify
- Check
Jobtable in SQL Server: newJdeNumbercolumn present and unique.
- Check
๐ก Sample Code Snippets
Querying a Job by JdeNumber
using var context = new IrbyContext();
var job = await context.Jobs
.Include(j => j.FieldOffice)
.FirstOrDefaultAsync(j => j.JdeNumber == "JN-10023");
Console.WriteLine($"Job: {job.Name} (Office: {job.FieldOffice.Name})");
๐ UML Diagram
classDiagram
class Job {
+Guid JobId
+string JdeNumber
+Guid? FieldOfficeId
+Guid? ManagerId
+Guid? ProjectManagerId
+Guid? SuperintendentId
+string Name
}
class FieldOffice {
+Guid Id
+string Name
// โฆ
}
Job --> FieldOffice : FieldOfficeId
Copy into Mermaid Live Editor for visualization.
๐ View Models & APIs
- ๐ View Models: N/A
- ๐ API Endpoints: N/A
This file purely concerns EF Core schema snapshot.
๐ ๏ธ Helper Methods & Utilities
BuildTargetModel: The sole methodโno additional utilities.- No manually authored helpers present.
๐ซ Error Handling & Return Types
- Error Handling: Not applicable; this is metadata.
- Return Types:
voidforBuildTargetModel. - Exceptions: EF Core may throw during migrations if the model is invalid.
๐ Thirdโparty Integrations
None in this designer file.
It references only Microsoft EF Core namespaces.
๐ Conclusion
The AddColumnsToJobTable.Designer.cs is a critical part of the EF Core migration machinery. It captures a complete snapshot of your domain model at migration time, allowing EF Core to:
- Compute diffs between models.
- Generate reliable Up() / Down() scripts.
- Maintain a versioned history of your database schema.
๐ง Tip: Treat it as readโonlyโgenerated code. Focus your customizations on the
Up()/Down()methods or your domain classes.