📚 Documentation: 20220520152658_AddFormsTable.Designer.cs
🗂️ Table of Contents
- Overview & Purpose
- EF Core Migrations Primer
- Migration Class Structure
- BuildTargetModel Method
- Key Data Models & Entities
- Entity Relationships
- Usage & Code Examples
- Mermaid UML Diagram
- Applying & Reverting the Migration
- Conclusion
1. Overview & Purpose
🔎 File:
IrbyImaging.DbContext/Migrations/20220520152658_AddFormsTable.Designer.cs
Purpose:
This designer file is an Entity Framework Core snapshot of your database model at the point of the AddFormsTable migration. It captures:
- The complete model (all tables & relationships).
- The new
IrbyFormstable introduced in this migration. - Metadata annotations (SQL Server identity, column types, constraints).
Why It Matters
EF Core uses this snapshot to compute the differences between your model and the target database when you add/revert migrations.
2. EF Core Migrations Primer
- Migrations: Version-controlled transformations of your database schema.
- Designer Files: Auto-generated C# classes storing the model snapshot.
- Up/Down Methods: Apply or remove schema changes.
- BuildTargetModel: Reconstructs the current model in code.
3. Migration Class Structure
[DbContext(typeof(IrbyContext))]
[Migration("20220520152658_AddFormsTable")]
partial class AddFormsTable : Migration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// Fluent API calls to configure entities...
}
}
- Attributes
[DbContext]: Links to yourIrbyContext.[Migration("...")]: Timestamp + descriptive name.
- Partial Class: Complements the main migration file (
Up/Downmethods).
4. BuildTargetModel Method
🔧 What It Does:
- Defines all entities (tables), columns, keys, indexes.
- Annotates database provider details (e.g., SQL Server Identity).
- Establishes relationships via Fluent API.
Note: Although your migration specifically adds
IrbyForms, the model snapshot lists every entity in your domain.
5. Key Data Models & Entities
5.1 IrbyForms Table (New) 🆕
| Column Name | CLR Type | SQL Type | Constraints |
|---|---|---|---|
| FormId | Guid |
uniqueidentifier |
Primary Key |
| DocumentUploadedBy | string |
nvarchar(max) |
|
| DocumentUploadedDate | DateTime |
datetime2 |
|
| FormName | string |
nvarchar(max) |
|
| FormNumber | string |
nvarchar(max) |
|
| ImageContents | byte[] |
varbinary(max) |
📝 Description:
TheIrbyFormstable stores uploaded form metadata & binary image contents for scanned paper forms.
5.2 Other Domain Entities (Snapshot)
Below is a brief summary. The full model includes ~40 entities:
| Category | Example Entities | Notes |
|---|---|---|
| Assets | Asset, Computer, MobileDevice, Printer, Monitor, … |
TPH inheritance via Discriminator column. |
| Billing | BillingInvoice, CarrierType, GeneralLedger, GLTypeDetail |
Financial & invoicing tables. |
| Document Mgmt | DocumentImage, IPMMigration, TempDocumentData, CovidTestData |
OCR & archival data. |
| HR & Jobs | Employee, FieldOffice, Job, ODS_Employee_Staging, ODS_Jobs_Staging |
Onboarding, staging from ODS. |
| Support | Ticket, Update, Issue |
Helpdesk ticketing system. |
| Utilities | RequestOption, OperatingSystem, Manufacturer, … |
Lookup/reference tables. |
6. Entity Relationships
🔗 Highlights:
- Asset → FieldOffice, Asset → Employee (Owner), Asset → AssetModel
- AssetModel → Manufacturer
- Employee → Job
- Ticket → Update
- Computer/SafetyEquipment → OperatingSystem
Example Fluent API snippet:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => { b.HasKey("Id"); b.HasOne("IrbyImaging.DomainClasses.Employee", "Owner") .WithMany("Assets") .HasForeignKey("OwnerId"); // ... });
7. Usage & Code Examples
7.1 Adding the Migration
# From project root
dotnet ef migrations add AddFormsTable \
--context IrbyContext \
--output-dir Migrations
7.2 Applying to Database
# Updates your database to the latest migration (applies BuildTargetModel)
dotnet ef database update --context IrbyContext
7.3 Inspecting Generated SQL
dotnet ef migrations script \
--from 20220520152657_PreviousMigration \
--to 20220520152658_AddFormsTable
8. Mermaid UML Diagram
erDiagram
IRBYFORMS {
GUID FormId PK
string FormName
string FormNumber
datetime DocumentUploadedDate
string DocumentUploadedBy
binary ImageContents
}
ASSET ||--o{ ASSETMODEL : belongs_to
ASSET ||--o{ FIELD_OFFICE : located_at
EMPLOYEE ||--o{ ASSET : owns
TICKET ||--o{ UPDATE : has
🌐 Tip: You can paste the above in VSCode or a Mermaid live editor to visualize the schema.
9. Applying & Reverting the Migration
| Action | Command |
|---|---|
| Apply all pending migrations | dotnet ef database update --context IrbyContext |
| Revert one migration | dotnet ef database update 20220520152657_PreviousMigration |
| Remove last migration | dotnet ef migrations remove --context IrbyContext |
10. Conclusion
🎉 You’ve learned:
- The role of Designer.cs in EF Core migrations.
- How
BuildTargetModelrepresents your complete domain at the migration point. - The new
IrbyFormstable schema & its columns. - Commands to add, apply, and revert migrations.
Next Steps:
- Review the main migration file (
20220520152658_AddFormsTable.cs) for theUp/Downlogic.- Run
database updatein development to create theirby.IrbyFormstable.- Extend your DbContext with
DbSet<IrbyForm>to query the new table.
🚀 Happy Coding!