📦 Migration Designer Documentation
File: IrbyImaging.DbContext/Migrations/20230719191116_AddUserApprovedToTicketTable.Designer.cs
Migration: 20230719191116_AddUserApprovedToTicketTable
DbContext: IrbyContext
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration File Structure
- BuildTargetModel Method
- Data Models & Entities
- Relationships & Mappings
- Third‑party Integrations
- Usage & Examples
- UML Diagram
- Conclusion 🎉
1. Overview & Purpose
This auto‑generated designer file is part of an EF Core migration that adds a new boolean column UserApproved to the Ticket table.
- It contains the snapshot of the entire model after this migration.
- EF Core uses it to compare schema changes and update the database reliably.
🎯 Key Goal: Ensure that the Ticket entity now includes a UserApproved flag so that application code and SQL schema remain in sync.
2. Dependencies & Technologies
| Component | Version / Notes |
|---|---|
| .NET SDK | 7.0+ |
| Microsoft.EntityFrameworkCore | 7.0.7 |
| Microsoft.EntityFrameworkCore.SqlServer | 7.0.7 |
| Microsoft.EntityFrameworkCore.Design | 7.0.7 |
| C# | 10+ |
No additional third‑party libraries beyond EF Core and SQL Server provider.
3. Migration File Structure
namespace IrbyImaging.DbContext.Migrations
{
[DbContext(typeof(IrbyContext))]
[Migration("20230719191116_AddUserApprovedToTicketTable")]
partial class AddUserApprovedToTicketTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// ... auto‑generated model definitions
}
}
}
- Attributes
[DbContext(typeof(IrbyContext))]ties it to yourIrbyContext.[Migration("20230719191116_AddUserApprovedToTicketTable")]gives it a timestamped identifier.
- Key Method
BuildTargetModel(ModelBuilder modelBuilder)– builds the full EF model snapshot representing your domain.
4. BuildTargetModel Method
This method uses the Fluent API to define:
- Global Annotations
modelBuilder .HasAnnotation("ProductVersion", "7.0.7") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - Entities
- Calls
modelBuilder.Entity("Namespace.ClassName", b => { … })for every domain class. - Defines properties, column types, keys, indexes, table schemas (
ToTable("…", "irby")).
- Calls
- Inheritance (TPH)
- The
Assetbase class and its derived types (Computer,MobileDevice, etc.) share the same table via a Discriminator column.
- The
- Relationships
- Configured via
.HasOne(…),.WithMany(…),.HasForeignKey(…), and.OnDelete(DeleteBehavior.Cascade).
- Configured via
5. Data Models & Entities
Below are key entities impacted or defined in this snapshot:
5.1. Ticket 📝
| Property | CLR Type | SQL Type | Notes |
|---|---|---|---|
| Id | Guid | uniqueidentifier | PK, ValueGeneratedOnAdd |
| CreatedOn | DateTime | datetime2 | |
| Status | int | int | |
| Type | int | int | |
| UserApproved | bool | bit | New flag indicating user approval (default: false) |
Migration Impact:
- Adds the
UserApprovedcolumn (bit) to theTickettable.
5.2. Update 📄
Tracks a ticket’s lifecycle changes.
- FK:
TicketId→Ticket.Id - Properties:
Id,Description,RequestedStatusJson,Timestamp,UpdatedBy.
5.3. Asset & Derived Types 🖥️
A Table‑Per‑Hierarchy strategy for Asset and subtypes:
- Base Table:
irby.Asset - Discriminator values:
"Asset","Computer","MobileDevice", etc. - Common Props:
Id,Category,Status,PurchaseDate, …
5.4. Employee 👷♂️
Stores company staff details:
- Unique index on
JdeNumber. - FKs: Department, Job, Role.
- Navigation collections:
Assets,TimeSheetEntries.
5.5. FieldOffice 🏢
Represents a physical office location.
- FKs: Manager, ProjectManager, Superintendent (all to
Employee).
…and many additional entities (Customer, Department, DocumentType, TimeSheetEntry, etc.)
6. Relationships & Mappings
- One-to-Many
Ticket (1)→Update (0..*)Employee (1)→TimeSheetEntry (0..*)
- One-to-One / Optional
Asset→Employee(Owner can be null)
- Many-to-One
Asset→AssetModelAssetModel→Manufacturer
- Inheritance (TPH)
- Shared
Assettable, uses.HasDiscriminator<string>("Discriminator").
- Shared
All cascade rules and delete behaviors are explicitly configured.
7. Third‑party Integrations
- EF Core SQL Server Provider for table creation, identity columns, and SQL types.
- No other third‑party APIs are directly referenced in this designer file.
8. Usage & Examples
8.1. Applying the Migration
# .NET CLI
dotnet ef database update 20230719191116_AddUserApprovedToTicketTable
# Package Manager Console
Update-Database -Migration 20230719191116_AddUserApprovedToTicketTable
8.2. Accessing the New Flag in Code
using var ctx = new IrbyContext();
var ticket = ctx.Tickets.Find(ticketId);
if (ticket.UserApproved)
{
Console.WriteLine("✅ Ticket has been approved by the user.");
}
else
{
Console.WriteLine("⏳ Awaiting user approval.");
}
8.3. Fluent API Override (Optional)
If you wish to set a default in your DbContext:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Ticket>()
.Property(t => t.UserApproved)
.IsRequired()
.HasDefaultValue(false);
}
9. UML Diagram
@startuml
class Ticket {
+ Guid Id
+ DateTime CreatedOn
+ int Status
+ int Type
+ bool UserApproved
}
class Update {
+ Guid Id
+ Guid TicketId
+ string Description
+ DateTime Timestamp
}
Ticket "1" --> "0..*" Update : hasUpdates
@enduml
10. Conclusion 🎉
This designer file is the EF Core snapshot of your domain after the AddUserApprovedToTicketTable migration. It captures all entities, properties, relationships, and the new UserApproved flag on the Ticket table.
- Always review auto‑generated migrations to confirm that schema changes meet your business requirements.
- Use the code snippets above to interact with the new column in your application.
Enjoy seamless database evolution with EF Core migrations!