📋 IrbyImaging.DbContext Migration: 20230822130112_AddAuditTable.Designer.cs
Auto‑generated EF Core migration designer file for the
AddAuditTablemigration.
Contains the target model snapshot used by Entity Framework Core to build or update the database schema.
🗂 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models Registered
- EF Core Fluent API Mappings
- UML Diagram
- Usage & Applying the Migration
- Conclusion
1. Overview & Purpose
This designer file is auto‑generated by Entity Framework Core (EF Core) as part of the AddAuditTable migration.
It defines the structure of the database model (all entities, their properties, keys, indices, and relationships) as EF Core expects it after applying this migration.
- Class:
AddAuditTable - Namespace:
IrbyImaging.DbContext.Migrations - Key Method:
This override instructs EF Core how to build the complete model snapshot.protected override void BuildTargetModel(ModelBuilder modelBuilder)
Why this matters
- Ensures consistency between your C# domain classes and the SQL Server schema.
- Allows EF Core tools to scaffold the next migration by comparing your current domain model to this snapshot.
2. Dependencies & Technologies
| Technology | Version / Role |
|---|---|
| .NET | 7.0.7 |
| C# | 10+ |
| Entity Framework Core | 7.0.7 |
| Database Provider | Microsoft SQL Server (SqlServerModelBuilderExtensions) |
| Primary Libraries | Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Migrations |
3. Key Functional Areas
- Model Annotations
ProductVersion:"7.0.7"Relational:MaxIdentifierLength:128
- Identity Columns
- Globally enabled via
UseIdentityColumns()
- Globally enabled via
- Entity Registrations
- Configures 100+ domain classes (e.g.,
Asset,Employee,AuditDetail, etc.) - Sets up inheritance (TPH) for Asset sub‑types (Computer, Monitor, MobileDevice…)
- Configures 100+ domain classes (e.g.,
- Relationships & Navigation
- Foreign keys, cascading behaviors, and
.HasIndex()definitions
- Foreign keys, cascading behaviors, and
- Newly Added Audit Table
AuditDetailentity and its mapping (core of this migration)
4. Data Models Registered
4.1 AuditDetail Table 💾
This migration introduces the AuditDetail entity to capture user/audit trails (e.g., controller actions, IP, timestamps).
Table Mapping
| EF Entity | Schema | Table Name |
|---|---|---|
AuditDetail |
"irby" |
"AuditDetail" |
Columns & Properties
| Property | CLR Type | SQL Type | Notes |
|---|---|---|---|
| AuditDetailId | Guid |
uniqueidentifier |
Primary Key |
| ActionName | string |
nvarchar(max) |
Action (method) name |
| ActivityDate | DateTime |
datetime2 |
When the action occurred |
| Area | string |
nvarchar(max) |
MVC Area (if any) |
| ControllerName | string |
nvarchar(max) |
MVC Controller |
| DocumentImageId | Guid? |
uniqueidentifier |
FK → DocumentImage (optional) |
| EmployeeId | Guid? |
uniqueidentifier |
FK → Employee |
| IpAddress | string |
nvarchar(max) |
Client IP |
| IsFirstLogin | string |
nvarchar(max) |
True/false as string |
| LangId | string |
nvarchar(max) |
Language identifier |
| LoginStatus | string |
nvarchar(max) |
e.g., Success/Failure |
| Namespace | string |
nvarchar(max) |
.NET namespace of the controller |
| PageAccessed | string |
nvarchar(max) |
The URL path |
| RoleId | Guid? |
uniqueidentifier |
FK → Role |
| SessionId | string |
nvarchar(max) |
ASP.NET Session ID |
| UrlReferrer | string |
nvarchar(max) |
HTTP Referrer header |
| UserId | Guid |
uniqueidentifier |
ID of the user performing the action |
Keys & Indexes
- Primary Key
b.HasKey("AuditDetailId"); - Indexes
EmployeeId→ speeds up user look‑upsRoleId→ quick role‑based queries
Relationships
EmployeeId→Employee(nullable)RoleId→Role(nullable)DocumentImageId→DocumentImage(nullable)
Configured via:
b.HasOne("IrbyImaging.DomainClasses.Employee", "User")
.WithMany()
.HasForeignKey("EmployeeId");
b.HasOne("IrbyImaging.DomainClasses.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
4.2 Other Entities (Summary)
The migration snapshot includes the full domain model (100+ tables). Below is a concise list of major entities:
| Category | Examples |
|---|---|
| Asset Management | Asset, AssetModel, AssetHistory, Computer, Monitor, MobileDevice, … |
| User & Security | Employee, Role, Permissions, LinkUserRole, LinkRolePermission |
| Billing & GL | BillingInvoice, GeneralLedger, GLTypeDetail |
| Imaging & Documents | DocumentImage, DocumentType, DocumentCategory, DocumentAttribute, … |
| Time Tracking | TimeSheetEntry, TimeEntryType |
| Support & Tickets | Ticket, Update, Issue |
| 3rd‑Party Sync | ODSEmployee, ODSJob, ODSCustomer |
5. EF Core Fluent API Mappings
The BuildTargetModel method uses the Fluent API to configure:
- Annotations
modelBuilder .HasAnnotation("ProductVersion", "7.0.7") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - Entity Definitions
.Entity("Fully.Qualified.Clr.Type", b => { … })- Property mapping:
b.Property<Guid>("Id") .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier");
- Inheritance (TPH)
- Single table for asset sub‑types (discriminator on
"Discriminator"column)
- Single table for asset sub‑types (discriminator on
- Indexes & Keys
b.HasKey("Id"); b.HasIndex("SomeForeignKey"); b.HasIndex("UniqueProperty").IsUnique().HasFilter("[Col] IS NOT NULL"); - Relationships
b.HasOne("ParentType", "NavProperty") .WithMany("CollectionNav") .HasForeignKey("ForeignKeyColumn") .OnDelete(DeleteBehavior.Cascade);
6. UML Diagram
classDiagram
class AuditDetail {
+Guid AuditDetailId
+string ActionName
+DateTime ActivityDate
+string Area
+string ControllerName
+Guid? DocumentImageId
+Guid? EmployeeId
+string IpAddress
+string IsFirstLogin
+string LangId
+string LoginStatus
+string Namespace
+string PageAccessed
+Guid? RoleId
+string SessionId
+string UrlReferrer
+Guid UserId
}
AuditDetail "0..1" <-- "1" Employee : EmployeeId
AuditDetail "0..1" <-- "1" Role : RoleId
AuditDetail "0..1" <-- "1" DocumentImage : DocumentImageId
7. Usage & Applying the Migration
- Add the Migration
dotnet ef migrations add AddAuditTable - Update the Database
dotnet ef database update - Result
- A new
irby.AuditDetailtable is created. - All existing schema objects remain intact.
- A new
8. Conclusion
This designer file is a critical piece of the EF Core migration pipeline. It captures the entire database model after applying the AddAuditTable migration, ensuring:
- Consistency between your C# domain classes and SQL schema.
- Safe evolution of the database over time.
- Smooth scaffolding of future migrations.
Enjoy your new audit trail capabilities! 📑🔍