π NewTimeEntryTypeTables.Designer.cs Documentation
File Path:
IrbyImaging.DbContext/Migrations/20230706154136_NewTimeEntryTypeTables.Designer.csPurpose:
This autoβgenerated designer file defines the complete EF Core model snapshot at the point of the20230706154136_NewTimeEntryTypeTablesmigration. It instructs EF Core how to build the database schema (tables, columns, keys, relationships, inheritance) for theIrbyContext.
π Table of Contents
- Overview & Purpose
- Migration Class Anatomy
- BuildTargetModel Method
- Core Concepts & Technologies
- Key Domain Entities & Relationships
- Configuration Annotations & Conventions
- How to Use This Migration
- UML Class Diagram (Simplified)
- Conclusion
1. Overview & Purpose
This .Designer.cs file is automatically generated by Entity Framework Core when you scaffold or add a migration. It contains:
- A snapshot of the entire model (all entities, properties, keys, relationships, inheritance).
- EF Core annotations (e.g. SQL Server identity columns, max identifier length).
- Mapping directives (table names, schemas, column types).
Why It Matters:
DuringUpdateβDatabase, EF Core compares this snapshot against the current database and generates SQL to apply pending migrations.Note: Do not manually edit this file; changes should be made via your domain classes or
migrationBuilderin the corresponding.csmigration file.
2. Migration Class Anatomy
[DbContext(typeof(IrbyContext))]
[Migration("20230706154136_NewTimeEntryTypeTables")]
partial class NewTimeEntryTypeTables : Migration
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// β¦ autoβgenerated model snapshot β¦
}
}
- DbContext Annotation
Links this migration to theIrbyContextclass. - Migration Attribute
Identifies the unique timestamped name of the migration. - BuildTargetModel
Core method that reconstructs the EF Core model using theModelBuilderAPI.
3. BuildTargetModel Method
Inside BuildTargetModel, EF Core:
- Sets Global Annotations
modelBuilder .HasAnnotation("ProductVersion", "7.0.7") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - Defines Entities
For each domain class, anEntity(...)block configures:- Properties (
Property<T>(),HasColumnType(),IsRequired(),ValueGeneratedOnAdd()) - Keys (
HasKey()) - Indexes (
HasIndex()) - Table Mapping (
ToTable("Name", "Schema")) - Inheritance and Discriminator when using TableβPerβHierarchy.
- Properties (
- Configures Relationships
UsingHasOne(...).WithMany(...)orHasOne(...).WithOne(...), plus cascade rules. - Navigation Properties
Registered via.Navigation("PropertyName").
4. Core Concepts & Technologies
| Technology | Purpose |
|---|---|
| Entity Framework Core | ORM framework to map C# classes to relational database tables. |
| Migrations | Track and apply incremental schema changes. |
ModelBuilder API |
Fluent API to define entity shapes and relationships. |
| SQL Server Provider | UseIdentityColumns(), HasColumnType("uniqueidentifier"), etc. |
| TableβPerβHierarchy | Single table for inheritance hierarchies with a discriminator column. |
5. Key Domain Entities & Relationships
5.1 π₯ New Tables: TimeEntryType & TimeSheetEntry
These two tables are added by this migration to support a timesheet feature:
TimeEntryType
| Property | Type | Constraints |
|---|---|---|
Id |
Guid | Primary Key |
Name |
string | β |
AddedBy |
string | β |
AddedDate |
DateTime | β |
ModifiedBy |
string | β |
ModifiedDate |
DateTime | β |
IsDeleted |
bool | Softβdelete flag |
modelBuilder.Entity("IrbyImaging.DomainClasses.TimeEntryType", b =>
{
b.Property<Guid>("Id").HasColumnType("uniqueidentifier");
b.Property<string>("Name").HasColumnType("nvarchar(max)");
b.Property<string>("AddedBy").HasColumnType("nvarchar(max)");
b.Property<DateTime>("AddedDate").HasColumnType("datetime2");
b.Property<string>("ModifiedBy").HasColumnType("nvarchar(max)");
b.Property<DateTime>("ModifiedDate").HasColumnType("datetime2");
b.Property<bool>("IsDeleted").HasColumnType("bit");
b.HasKey("Id");
b.ToTable("TimeEntryType", "irby");
});
TimeSheetEntry
| Property | Type | Constraints |
|---|---|---|
Id |
Guid | Primary Key |
EmployeeId |
Guid? | FK β Employee(Id) |
TimeEntryTypeId |
Guid? | FK β TimeEntryType(Id) |
DateWorked |
DateTime | Column type Date |
HoursWorked |
decimal | Precision (18,2) |
AddedBy |
string | β |
AddedDate |
DateTime | β |
ModifiedBy |
string | β |
ModifiedDate |
DateTime | β |
IsDeleted |
bool | Softβdelete flag |
modelBuilder.Entity("IrbyImaging.DomainClasses.TimeSheetEntry", b =>
{
b.Property<Guid>("Id").HasColumnType("uniqueidentifier");
b.Property<Guid?>("EmployeeId").HasColumnType("uniqueidentifier");
b.Property<Guid?>("TimeEntryTypeId").HasColumnType("uniqueidentifier");
b.Property<DateTime>("DateWorked").HasColumnType("Date");
b.Property<decimal>("HoursWorked").HasColumnType("decimal(18,2)");
b.Property<string>("AddedBy").HasColumnType("nvarchar(max)");
b.Property<DateTime>("AddedDate").HasColumnType("datetime2");
b.Property<string>("ModifiedBy").HasColumnType("nvarchar(max)");
b.Property<DateTime>("ModifiedDate").HasColumnType("datetime2");
b.Property<bool>("IsDeleted").HasColumnType("bit");
b.HasKey("Id");
b.ToTable("TimeSheetEntry", "irby");
// Relationships
b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
.WithMany()
.HasForeignKey("EmployeeId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("IrbyImaging.DomainClasses.TimeEntryType", "TimeEntryType")
.WithMany()
.HasForeignKey("TimeEntryTypeId")
.OnDelete(DeleteBehavior.Cascade);
});
5.2 π§ Asset Inheritance (TPH Mapping)
All IrbyImaging.DomainClasses.Asset and its derived types share a single table:
- Table:
irby.Asset - Discriminator Column:
Discriminator - Derived Types:
Computer,DeskPhone,Dock,MobileDevice,Monitor,NetworkEquipment,OfficePrinter,Printer,SafetyEquipment
5.3 π Other Core Entities (Overview)
This migration snapshot also includes many existing tables such as:
| Entity | Table | Key(s) | Notes |
|---|---|---|---|
Customer |
irby.Customer |
Id (GUID) |
β |
Employee |
irby.Employee |
Id (GUID) |
Unique JdeNumber |
Job |
irby.Job |
Id (GUID) |
Unique JdeNumber |
DocumentImage |
irby.DocumentImage |
DocumentImageId (GUID) |
OCR / blob storage |
Ticket & Update |
irby.Ticket, irby.Update |
Id (GUID) |
1βtoβmany: TicketβUpdates |
GeneralLedger & GLTypeDetail |
irby.GeneralLedger, GLTypeDetail |
Id (GUID) |
1βtoβmany |
β¦plus many other staging tables (ODS_Employee_Staging, IPMMigration, CovidTestData, β¦).
6. Configuration Annotations & Conventions
- Product Version:
"7.0.7" - Max Identifier Length:
128 - SQL Server Identity:
UseIdentityColumns()for integer primary keys. - Column Types: Explicit
HasColumnType(...)calls ensure correct SQL types. - SoftβDelete Pattern: Many entities have an
IsDeletedboolean.
7. How to Use This Migration
- Add Migration
dotnet ef migrations add NewTimeEntryTypeTables - Review Generated Files
20230706154136_NewTimeEntryTypeTables.cs(Contains theUp()/Down()migration code)- THIS
β¦NewTimeEntryTypeTables.Designer.cs(Model snapshot)
- Apply to Database
dotnet ef database update - Verify
- Two new tables
irby.TimeEntryTypeandirby.TimeSheetEntryexist - FKs to
EmployeeandTimeEntryTypeenforce referential integrity
- Two new tables
8. UML Class Diagram (Simplified)
βββββββββββββββββββββββ βββββββββββββββββββββββββ
β TimeEntryType β β Employee β
βββββββββββββββββββββββ βββββββββββββββββββββββββ
β + Id : Guid β1 * β + Id : Guid β
β + Name : string βββββββββββββΊβ + DisplayName : stringβ
β + AddedBy β β β¦ β
β β¦ β βββββββββββββββββββββββββ
βββββββββββββββββββββββ
β²
β
β
1 β
βββββββββββββββββββββββ
β TimeSheetEntry β
βββββββββββββββββββββββ
β + Id : Guid β
β + DateWorked: Date β
β + HoursWorked: dec β
β + EmployeeId : Guid?β
β + TimeEntryTypeId:G β
β β¦ β
βββββββββββββββββββββββ
9. Conclusion
This designer file is the blueprint EF Core uses to:
- Reconstruct the entire domain model at this migration point.
- Validate model vs database schema.
- Generate SQL for
UpdateβDatabase.
By reviewing it, you gain deep insight into:
- Table structures
- Column types & constraints
- Relationships & cascade rules
- Inheritance mapping strategies
π Tip: Always make schema changes by updating your domain classes or the core
Up()/Down()migration file. Let EF Core maintain this snapshot automatically.