📑 Index
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Model Configuration
- Inheritance & Table‑Per‑Hierarchy (TPH)
- Relationships & Navigation Properties
- Code Snippets
- Usage Examples
- UML Class Diagram (Mermaid)
- Conclusion
1. Overview & Purpose 🚀
File: IrbyImaging.DbContext/Migrations/20231219151103_RemoveIsPdfPortfolioColumn.Designer.cs
This is an auto‑generated EF Core migration designer file. It captures the target data model (post‑migration) so that Entity Framework Core knows how the database schema should look after applying the RemoveIsPdfPortfolioColumn migration.
- Why?
EF Core uses this snapshot to calculate the differences (model diffs) between your C# classes and the actual database schema. - What it does?
Implements theBuildTargetModel(ModelBuilder modelBuilder)method, which re‑defines every entity, property, relationship, table mapping, and inheritance mapping in code. - Do not modify manually!
Changes to this file will be overwritten by EF Core whenever you add a new migration.
2. Dependencies & Technologies ⚙️
| Technology | Version / Package |
|---|---|
| .NET SDK | .NET 7.0 (apparently EF Core 7.0.7) |
| Entity Framework Core | Microsoft.EntityFrameworkCore (7.0.7) |
| EF Core SQL Server Provider | Microsoft.EntityFrameworkCore.SqlServer |
| EF Core Migrations Infrastructure | Microsoft.EntityFrameworkCore.Design |
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
3. Key Functional Areas 🛠️
-
Model‐Level Annotations
modelBuilder.HasAnnotation("ProductVersion", "7.0.7")Relational:MaxIdentifierLength,UseIdentityColumns()
-
Entity Definitions
- One call to
modelBuilder.Entity(...)per domain class. - Columns defined via
b.Property<type>(name).HasColumnType(...). - Primary keys with
b.HasKey(...). - Indexes via
b.HasIndex(...). - Table and schema mapping:
b.ToTable("Name", "irby").
- One call to
-
Inheritance Mapping (TPH)
- Discriminator column:
b.HasDiscriminator<string>("Discriminator"). - Child entities (e.g.,
Computer,DeskPhone, etc.) map back to the baseAssettable.
- Discriminator column:
-
Relationships
b.HasOne(...).WithMany(...).HasForeignKey(...).OnDelete(...).
4. Data Model Configuration 📦
Below is a condensed table of a few key entities (out of dozens):
| Entity | Table (Schema) | Key | Sample Properties |
|---|---|---|---|
| Asset | irby.Asset | Id (Guid) |
Category, ModelId, OwnerId, PurchaseDate, Status |
| AssetModel | irby.AssetModel | Id (int) |
Name, MakeId, Category, IsAvailableOption |
| Employee | irby.Employee | EmployeeId (Guid) |
FirstName, LastName, Email, RoleId, Status |
| DocumentImage | irby.DocumentImage | DocumentImageId (Guid) |
FileName, BlobName, ContentType, Page, TotalPages |
| TimeSheetEntry | irby.TimeSheetEntry | TimeSheetEntryId (Guid) |
DateWorked, HoursWorked, EmployeeId, TimeEntryTypeId |
Tip: The full file contains 50+ entity definitions, each mapping C# domain classes to SQL tables and columns.
5. Inheritance & Table‑Per‑Hierarchy (TPH) 🌲
EF Core uses single-table inheritance for the Asset hierarchy. All sub‑types share the same irby.Asset table, distinguished by the Discriminator column.
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
b.HasDiscriminator<string>("Discriminator")
.HasValue("Asset");
b.UseTphMappingStrategy();
});
// Sub-types
modelBuilder.Entity("IrbyImaging.DomainClasses.Computer", b => {
b.HasBaseType("IrbyImaging.DomainClasses.Asset");
b.HasDiscriminator().HasValue("Computer");
});
modelBuilder.Entity("IrbyImaging.DomainClasses.DeskPhone", b => {
b.HasBaseType("IrbyImaging.DomainClasses.Asset");
b.HasDiscriminator().HasValue("DeskPhone");
});
// …and so on for Dock, MobileDevice, Monitor, etc.
6. Relationships & Navigation Properties 🔗
6.1 Asset ↔ Owner (Employee)
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b => {
b.HasOne("IrbyImaging.DomainClasses.Employee", "Owner")
.WithMany("Assets")
.HasForeignKey("OwnerId");
});
- One Employee can own many Assets.
- Foreign key:
Asset.OwnerId→Employee.EmployeeId.
6.2 AssetModel ↔ Manufacturer (Make)
modelBuilder.Entity("IrbyImaging.DomainClasses.AssetModel", b => {
b.HasOne("IrbyImaging.DomainClasses.Manufacturer", "Make")
.WithMany("Models")
.HasForeignKey("MakeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
- One Manufacturer → many AssetModel.
- Cascade delete: deleting a
Manufacturerremoves associatedAssetModels.
Note: There are many more relationships (e.g., FieldOffice–Assets, Employee–Role, Ticket–Updates). Refer to the full code for details.
7. Code Snippets 📝
7.1 BuildTargetModel Signature
[DbContext(typeof(IrbyContext))]
[Migration("20231219151103_RemoveIsPdfPortfolioColumn")]
partial class RemoveIsPdfPortfolioColumn
{
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
}
}
7.2 Sample Entity Configuration
modelBuilder.Entity("IrbyImaging.DomainClasses.Employee", b =>
{
b.Property<Guid>("EmployeeId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.HasKey("EmployeeId");
b.HasIndex("JdeNumber")
.IsUnique()
.HasFilter("[JdeNumber] IS NOT NULL");
b.ToTable("Employee", "irby");
});
8. Usage Examples ⚙️
8.1 Adding the Migration
dotnet ef migrations add RemoveIsPdfPortfolioColumn \
--context IrbyContext \
--output-dir Migrations
8.2 Applying to the Database
dotnet ef database update RemoveIsPdfPortfolioColumn \
--context IrbyContext
After generating, EF Core updates two files:
20231219151103_RemoveIsPdfPortfolioColumn.cs(containsUp()/Down())20231219151103_RemoveIsPdfPortfolioColumn.Designer.cs(this snapshot)
9. UML Class Diagram (Mermaid) 📊
classDiagram
%% Base Asset
class Asset {
+Guid Id
+string Category
+int ModelId
+Guid? FieldOfficeId
+Guid? OwnerId
+DateTimeOffset PurchaseDate
+string Status
// …
}
%% Subtypes
class Computer
class DeskPhone
class MobileDevice
class OfficePrinter
%% Relationships
Asset <|-- Computer
Asset <|-- DeskPhone
Asset <|-- MobileDevice
Asset <|-- OfficePrinter
%% Other Entities
class Employee {
+Guid EmployeeId
+string FirstName
+string LastName
+string Email
// …
}
Employee "1" -- "0..*" Asset : Owner
AssetModel "1" -- "0..*" Asset : Model
Manufacturer "1" -- "0..*" AssetModel : Make
10. Conclusion 🎯
The RemoveIsPdfPortfolioColumn.Designer.cs file is a critical snapshot of your EF Core model after removing the IsPdfPortfolio column. It ensures that EF Core knows how to recreate or migrate your schema correctly.
Key takeaways:
- Auto‑generated – do not hand-edit.
- Contains BuildTargetModel to redefine all entities, properties, indexes, and relationships.
- Used by EF Core to compute schema diffs & protect design‑time model integrity.
Keep your domain classes and migrations in sync, rely on EF Core CLI for adding/applying migrations, and let these designer files orchestrate the heavy lifting behind the scenes!
Happy Coding! 😊
Generated by Entity Framework Core Migrations.