📄 Documentation: 20240318231947_UpdateLegalDashDBtables2.Designer.cs
Path:
IrbyImaging.DbContext/Migrations/20240318231947_UpdateLegalDashDBtables2.Designer.cs
Generated by: Entity Framework Core (EF Core) Migrations
Purpose: Represents the snapshot of the EF Core model at the point of theUpdateLegalDashDBtables2migration, mapping domain classes to database tables, columns, keys, indexes, and relationships.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- BuildTargetModel Method
- Key Entity Mappings
- Relationships & Navigation Properties
- Example: Applying the Migration
- Mermaid UML Diagram (Sample)
- Conclusion
🔍 Overview & Purpose
This file is an auto-generated snapshot of the EF Core model builder configuration at the moment when the UpdateLegalDashDBtables2 migration was added. Its core responsibilities:
- Define tables (
ToTable) and schemas ("irby", default). - Map properties to columns (
HasColumnType, required/nullable, value generation). - Establish keys (
HasKey), indexes (HasIndex), and relational constraints (HasOne/WithMany). - Configure inheritance (Table‑per‑Hierarchy with
HasDiscriminatorfor assets).
💡 Why It Matters:
When you rundotnet ef database update, EF Core uses this snapshot to compute the SQL DDL needed to bring your database schema in line with your domain classes.
🛠 Dependencies & Technologies
- .NET 7.0 / C#
- Entity Framework Core 7.0.7
- Microsoft.EntityFrameworkCore.Relational (SQL Server provider)
- Microsoft.EntityFrameworkCore.Design (for migrations)
These packages enable code‑first migrations, database scaffolding, and schema evolution.
⚙️ BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "7.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
// SQL Server identity configuration
modelBuilder.UseIdentityColumns();
// Entity configurations follow...
}
modelBuilder.HasAnnotation: Captures EF Core version and provider-specific metadata.UseIdentityColumns: Configures SQL Server to useIDENTITYcolumns for key generation.- Invokes
modelBuilder.Entity("Namespace.DomainClass", b => { ... })for each mapped class.
🔑 Key Entity Mappings
Below is a selection of major domain classes and how they map to tables/schemas. The EF snapshot covers over 80 entity types; here we group & highlight representative ones.
4.1 Asset Management
| DomainClass | Table | PK | Notes |
|---|---|---|---|
Asset |
irby.Asset |
Id |
TPH base; discriminator: “Asset” |
Computer (subclass) |
irby.Asset |
Id |
Discriminator: “Computer”; links to OS |
MobileDevice |
irby.Asset |
Id |
Discriminator: “MobileDevice”; unique Imei |
AssetModel |
irby.AssetModel |
Id |
FK → Manufacturer (MakeId) |
AssetHistory |
irby.AssetHistory |
Id |
Historical changes, serialized JSON fields |
4.2 Auditing & Reporting
| DomainClass | Table | PK | Notes |
|---|---|---|---|
AuditDetail |
irby.AuditDetail |
AuditDetailId |
Tracks user actions, timestamps |
AuditReport |
AuditReport |
(no PK) | View model mapping for reporting |
LinkRolePermission |
irby.LinkRolePermission |
Id |
M:N between Role and Permissions |
4.3 Document Management
| DomainClass | Table | PK | Notes |
|---|---|---|---|
DocumentImage |
irby.DocumentImage |
DocumentImageId |
Main blob store, OCR content, multi‑flags |
DocumentAttribute |
irby.DocumentAttribute |
Id |
Defines index fields per document type |
DocumentType |
irby.DocumentType |
Id |
Lookup of document categories |
TempDocumentData |
irby.TempDocumentData |
TempDocumentDataId |
Staging area for uploads |
4.4 Field Offices & Jobs
| DomainClass | Table | PK | Notes |
|---|---|---|---|
FieldOffice |
irby.FieldOffice |
Id |
Links many Assets & Jobs |
Job |
irby.Job |
JobId |
Unique JdeNumber, FK → FieldOffice |
Employee |
irby.Employee |
EmployeeId |
FK → Job, unique JdeNumber |
4.5 ODS (External Data) Entities
| DomainClass | Table | PK | Notes |
|---|---|---|---|
ODSCustomer |
ODSCustomers |
(no PK) | External data import snapshot |
ODSEmployee |
ODSEmployees |
(no PK) | Many varbinary columns (ERP sync) |
ODSJob |
ODSJobs |
(no PK) | Mirror of job data from ODS system |
4.6 Ticketing & Time Tracking
| DomainClass | Table | PK | Notes |
|---|---|---|---|
Ticket |
irby.Ticket |
Id |
Service requests, review workflows |
Update |
irby.Update |
Id |
History of ticket status changes |
TimeSheetEntry |
irby.TimeSheetEntry |
TimeSheetEntryId |
FK → Employee, TimeEntryType |
TimeEntryType |
irby.TimeEntryType |
TimeEntryTypeId |
Lookup of entry categories |
🔗 Relationships & Navigation Properties
EF Core configures relationships via fluent API:
- One‑to‑Many:
modelBuilder.Entity<Asset>() .HasOne(a => a.FieldOffice) .WithMany(fo => fo.Assets) .HasForeignKey(a => a.FieldOfficeId); - Many‑to‑Many (via link entities):
modelBuilder.Entity<LinkUserRole>() .HasOne(lur => lur.User) .WithMany() // no direct navigation on Employee .HasForeignKey(lur => lur.EmployeeId); - TPH Inheritance (Assets):
b.HasDiscriminator<string>("Discriminator") .HasValue<Computer>("Computer") .HasValue<MobileDevice>("MobileDevice");
All navigations are configured at the end of
BuildTargetModel, wiring up FKs and cascade behaviors.
🚀 Example: Applying the Migration
- Add Migration
dotnet ef migrations add UpdateLegalDashDBtables2 - Review Generated SQL
dotnet ef migrations script -i - Update Database
dotnet ef database update
This will execute the DDL needed to align your SQL Server schema with the BuildTargetModel snapshot.
🖼️ Mermaid UML Diagram (Sample)
classDiagram
Asset <|-- Computer
Asset <|-- MobileDevice
Asset o-- AssetModel : ModelId
Asset o-- Employee : OwnerId
Asset o-- FieldOffice : FieldOfficeId
FieldOffice "1" o-- "*" Asset
FieldOffice "1" o-- "*" Job
Job "1" o-- "*" Employee
Employee "1" o-- "*" Asset
Ticket "1" o-- "*" Update
TimeSheetEntry "1" o-- 1 Employee
TimeSheetEntry "1" o-- 1 TimeEntryType
This simplified class diagram highlights core relationships.
🏁 Conclusion
UpdateLegalDashDBtables2.Designer.csis a complete snapshot of your EF Core model at a moment in time.- It ensures consistency between your C# domain classes and the SQL database.
- Do not manually edit this file—changes should be made to your domain classes or in a new migration.
- For extensive schema changes, always add a new migration and review the generated code/SQL.
Happy coding! 🚀