π IrbyImaging.DbContext/Migrations/20220303152541_AddFileName.Designer.cs Documentation
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- BuildTargetModel Method
- Entity Configurations
- Entity Relationships & Inheritance
- Applying Migrations & Usage Examples
- UML Diagrams
- Conclusion
1. Overview & Purpose π οΈ
This file, 20220303152541_AddFileName.Designer.cs, is an auto-generated portion of an Entity Framework Core (EF Core) migration named AddFileName. It lives in the IrbyImaging.DbContext.Migrations namespace and contains the model snapshot for your database schema after applying this migration.
- Filename:
Migrations/20220303152541_AddFileName.Designer.cs - Namespace:
IrbyImaging.DbContext.Migrations - EF Core Version: 5.0.12
- Generated On: 03β31β2022
- Purpose:
- Provide a snapshot of the EF Core model (tables, columns, keys, relationships)
- Used by EF Core tooling to diff schema changes when creating future migrations
2. Dependencies & Technologies π
| Technology | Version/Detail |
|---|---|
| .NET Runtime | .NET 5.0+ |
| Entity Framework Core | 5.0.12 |
| EF Core Migrations | Migration base class, CLI & Design-time APIs |
| Database Provider | Microsoft SQL Server (SqlServerValueGenerationStrategy.IdentityColumn) |
Namespaces Imported
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
3. Key Functional Areas π
- Model Snapshot Configuration
- BuildTargetModel: Central method to describe the entire EF model.
- Entity Type Registrations
- Defines each domain class (
Asset,Employee,DocumentImage, etc.).
- Defines each domain class (
- Table & Schema Mappings
- Specifies table names (e.g.,
"Asset") and schema (e.g.,"irby").
- Specifies table names (e.g.,
- Columns & Data Types
- Declares properties, their CLR types, database types (
nvarchar,uniqueidentifier, etc.).
- Declares properties, their CLR types, database types (
- Keys & Indexes
- Primary keys (
HasKey), alternate keys, foreign keys, indexes (HasIndex).
- Primary keys (
- Inheritance & Discriminators
- Single-table inheritance via
.HasDiscriminator()for asset subclasses (Computer, Monitorβ¦).
- Single-table inheritance via
- Relationships & Navigations
- One-to-many (
HasOne(...).WithMany(...)), cascade delete, navigation properties.
- One-to-many (
4. BuildTargetModel Method ποΈ
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.12")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// β¦ entity configurations β¦
#pragma warning restore 612, 618
}
- ModelBuilder: EF Coreβs fluent API entry point.
- HasAnnotation: Adds provider-specific metadata (e.g., SQL Server identity strategy).
- Entities are configured in sequential
modelBuilder.Entity("FullTypeName", b => { β¦ })blocks.
5. Entity Configurations π
Below is a sample of the hundreds of properties configured.
(Full file defines ~25 EF Core entities under irby schema.)
| Entity Type | Table (Schema) | Key | Notes |
|---|---|---|---|
| IrbyImaging.DomainClasses.Asset | Asset (irby) | Id: uniqueidentifier |
Base discriminator; shared columns |
| β’ Computer | Asset (irby) | Inherited | OperatingSystemId, AssetNumber, β¦ |
| β’ MobileDevice | Asset (irby) | Inherited | Unique Imei index; Carrier, Type |
| β’ DeskPhone | Asset (irby) | Inherited | MacAddress, PhoneNumber |
| IrbyImaging.DomainClasses.Employee | Employee (irby) | Id: uniqueidentifier |
Unique JdeNumber index |
| IrbyImaging.DomainClasses.FieldOffice | FieldOffice (irby) | Id |
Unique JdeNumber; manager FK |
| IrbyImaging.DomainClasses.DocumentImage | DocumentImage (irby) | DocumentImageId |
New property FileName added by migration |
| IrbyImaging.DomainClasses.AssetHistory | AssetHistory (irby) | Id |
Tracks asset changes |
| IrbyImaging.DomainClasses.Job | Job (irby) | Id |
Unique JdeNumber |
| β¦ and many more |
Spotlight: DocumentImage
The DocumentImage entity is the one extended by AddFileName migration.
b.Property<string>("FileName")
.HasColumnType("nvarchar(max)");
This column allows the application to store the original file name of uploaded documents.
6. Entity Relationships & Inheritance π
Inheritance (Single-Table)
All Asset-derived classes share one physical table with a Discriminator column:
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
b.HasDiscriminator<string>("Discriminator")
.HasValue("Asset");
});
modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b => {
b.HasBaseType("IrbyImaging.DomainClasses.Asset");
b.HasDiscriminator().HasValue("Computer");
});
Sample Foreign Keys
- Asset β Employee (Owner)
- Asset β FieldOffice (FieldOfficeId)
- AssetModelDetail β AssetModel
- Employee β Job (CurrentJobId)
- Computer β OperatingSystem
7. Applying Migrations & Usage Examples π
7.1 Creating a Migration
dotnet ef migrations add AddFileName
- Generates two files under
Migrations/20220303152541_AddFileName.*.cs- AddFileName.cs (Up/Down methods)
- AddFileName.Designer.cs (model snapshot)
7.2 Updating the Database
dotnet ef database update
- Applies pending migrations to your SQL Server database.
- Adds the
FileNamecolumn toirby.DocumentImagealong with any other changes.
7.3 Rolling Back
dotnet ef database update LastGoodMigrationName
- Reverts schema to the specified migration.
8. UML Diagrams π
Below is a Mermaid class diagram illustrating Asset inheritance and key relationships:
classDiagram
%% Base
Asset <|-- Computer
Asset <|-- MobileDevice
Asset <|-- DeskPhone
Asset <|-- Monitor
Asset <|-- OfficePrinter
Asset <|-- Dock
Asset <|-- Printer
Asset <|-- NetworkEquipment
Asset <|-- SafetyEquipment
%% Relationships
Asset o-- FieldOffice : FieldOfficeId
Asset o-- Employee : OwnerId
Asset o-- AssetModel : ModelId
Employee "1" o-- "*" Asset : Assets
FieldOffice "1" o-- "*" Asset : Assets
Job "1" o-- "*" Employee : Employees
AssetModel "1" o-- "*" AssetModelDetail : AssetsModelDetail
Manufacturer "1" o-- "*" AssetModel : Models
9. Conclusion π
The AddFileName.Designer.cs file is a critical part of EF Coreβs migrations infrastructure. It:
- π Describes the complete EF model after this migration
- π Enables EF to diff schema changes for future migrations
- π‘οΈ Is automatically generated and not typically hand-modified
By understanding its structure, you gain deep insight into your database schema, entity mappings, and how EF Core orchestrates your data layer.
Happy coding! π