ποΈ Documentation: UpdateLegalDashboardTables.Designer.cs
Path:
IrbyImaging.DbContext/Migrations/20240318162041_UpdateLegalDashboardTables.Designer.cs
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
3.1 Entity & Table Mappings
3.2 Inheritance & Discriminators
3.3 Relationships & Navigation - How It Works
4.1 BuildTargetModel Method
4.2 Fluent API Configuration - Usage & Examples
- UML Class Diagram (Simplified)
- Conclusion
π Overview & Purpose
This auto-generated .Designer.cs file is part of Entity Framework Coreβs migration system. It represents the target model snapshot after applying the UpdateLegalDashboardTables migration.
- Purpose:
- Captures table schemas, columns, keys, indexes, inheritance, and relationships.
- Enables EF Core to compare model changes and generate future migrations.
- Note:
- Do not manually edit this file.
- Use
dotnet ef migrations addanddotnet ef database updatecommands to create/apply migrations.
βοΈ Dependencies & Technologies
| Technology | Version | Role |
|---|---|---|
| .NET 7.0 | 7.0.7 | Target framework |
| Entity Framework Core | 7.x | ORM / Migrations |
| Microsoft.SqlServer | β | Underlying relational database provider |
| C# | 10+ | Programming language |
π Key Functional Areas
1. Entity & Table Mappings
The BuildTargetModel method configures 100+ domain entities. Each call to modelBuilder.Entity(...) maps a CLR class to a relational table.
Sample Table of Entities
| CLR Entity | Schema | Table Name | Primary Key |
|---|---|---|---|
Asset |
irby |
Asset |
Id : uniqueidentifier |
AssetHistory |
irby |
AssetHistory |
Id : uniqueidentifier |
DocumentImage |
irby |
DocumentImage |
DocumentImageId |
DocumentCategory |
irby |
DocumentCategory |
Id |
AuditDetail |
irby |
AuditDetail |
AuditDetailId |
Job |
irby |
Job |
JobId |
Employee |
irby |
Employee |
EmployeeId |
Permissions |
irby |
Permissions |
PermissionId |
Role |
irby |
Role |
RoleId |
| β¦and many more (ODS, Leasing, TimeSheet, IPMMigration, etc.) |
2. Inheritance & Discriminators
Certain tables use Table-Per-Hierarchy (TPH) to model inheritance:
- Asset
- Discriminator column:
Discriminator - Subclasses:
Computer(β addsAssetNumber,CpsNumber,OperatingSystemId,UnitNumber)MobileDevice(β addsCarrier,Imei,PhoneNumber, etc.)DeskPhone,Dock,Monitor,NetworkEquipment,OfficePrinter,Printer,SafetyEquipment
- Configured with
.UseTphMappingStrategy()and.HasDiscriminator(...).
- Discriminator column:
3. Relationships & Navigation
- One-to-Many
AssetβAssetHistoryJobβEmployeeFieldOfficeβJobs,AssetsTicketβUpdates
- Many-to-Many (via linking tables)
RoleβPermissions(LinkRolePermission)EmployeeβRole(LinkUserRole)
- Foreign Keys & Cascades
- Configured with
.HasForeignKey(...),.OnDelete(DeleteBehavior.Cascade)when required. - Indexes on FKs for performance.
- Configured with
π How It Works
BuildTargetModel Method
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// Enable IDENTITY columns for SQL Server
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
// Configure each entity...
modelBuilder.Entity("IrbyImaging.DomainClasses.Asset", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("nvarchar(max)");
// β¦ other props β¦
b.HasKey("Id");
b.ToTable("Asset", "irby");
b.HasDiscriminator<string>("Discriminator")
.HasValue("Asset");
});
// β¦ thousands of lines of entity configurations β¦
#pragma warning restore 612, 618
}
Fluent API Configuration
- Properties:
.HasColumnType(),.IsRequired(),.ValueGeneratedOnAdd() - Keys & Indexes:
.HasKey(),.HasIndex(),.IsUnique() - Table Mapping:
.ToTable("Name", "Schema") - Inheritance:
.HasDiscriminator(),.UseTphMappingStrategy() - Relationships:
.HasOne(...).WithMany(...).HasForeignKey(...)
βοΈ Usage & Examples
Applying the Migration
# From your project directory
dotnet ef migrations add UpdateLegalDashboardTables
dotnet ef database update 20240318162041_UpdateLegalDashboardTables
Inspecting the Model
You can use EF Core commands to view the model snapshot:
dotnet ef migrations script 20240318162041_UpdateLegalDashboardTables
Code-First Workflow
- Modify or add your domain classes and/or
DbContext. - Run
dotnet ef migrations add <YourMigrationName>. - Review the generated
.Designer.csfiles (snapshot). - Update database with
dotnet ef database update.
π§© UML Class Diagram (Simplified)
classDiagram
Asset <|-- Computer
Asset <|-- MobileDevice
Asset <|-- DeskPhone
AssetModel --> Manufacturer : Make
Asset --> AssetModel : Model
AssetHistory --> Asset : AssetId
DocumentImage --> DocumentCategory : DocumentType
Employee --> Department
Employee --> Job
Job --> FieldOffice
Role "1" <-- "M" LinkUserRole --> Employee "1"
Role "1" <-- "M" LinkRolePermission --> Permissions "1"
Ticket --> Update
TimeSheetEntry --> Employee
TimeSheetEntry --> TimeEntryType
π Conclusion
This migration snapshot is a comprehensive blueprint of the database schema for the IrbyImaging application after applying the UpdateLegalDashboardTables migration. It:
- Defines 100+ tables and their columns
- Configures keys, indexes, and relationships
- Models inheritance for assets
- Serves as a reference for EF Core to generate, apply, and revert migrations
π With this documentation you have both a conceptual and technical overview of how EF Core maps your domain model to a SQL Server database.