πŸ“„ NewTimeEntryTypeTables.Designer.cs Documentation


File Path:
IrbyImaging.DbContext/Migrations/20230706154136_NewTimeEntryTypeTables.Designer.cs

Purpose:
This auto‐generated designer file defines the complete EF Core model snapshot at the point of the 20230706154136_NewTimeEntryTypeTables migration. It instructs EF Core how to build the database schema (tables, columns, keys, relationships, inheritance) for the IrbyContext.


πŸ—‚ Table of Contents

  1. Overview & Purpose
  2. Migration Class Anatomy
  3. BuildTargetModel Method
  4. Core Concepts & Technologies
  5. Key Domain Entities & Relationships
  6. Configuration Annotations & Conventions
  7. How to Use This Migration
  8. UML Class Diagram (Simplified)
  9. 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:
During Update‑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 migrationBuilder in the corresponding .cs migration 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 the IrbyContext class.
  • Migration Attribute
    Identifies the unique timestamped name of the migration.
  • BuildTargetModel
    Core method that reconstructs the EF Core model using the ModelBuilder API.

3. BuildTargetModel Method

Inside BuildTargetModel, EF Core:

  1. Sets Global Annotations
    modelBuilder
      .HasAnnotation("ProductVersion", "7.0.7")
      .HasAnnotation("Relational:MaxIdentifierLength", 128);
    
    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
    
  2. Defines Entities
    For each domain class, an Entity(...) 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.
  3. Configures Relationships
    Using HasOne(...).WithMany(...) or HasOne(...).WithOne(...), plus cascade rules.
  4. 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 IsDeleted boolean.

7. How to Use This Migration

  1. Add Migration
    dotnet ef migrations add NewTimeEntryTypeTables
    
  2. Review Generated Files
    • 20230706154136_NewTimeEntryTypeTables.cs (Contains the Up() / Down() migration code)
    • THIS …NewTimeEntryTypeTables.Designer.cs (Model snapshot)
  3. Apply to Database
    dotnet ef database update
    
  4. Verify
    • Two new tables irby.TimeEntryType and irby.TimeSheetEntry exist
    • FKs to Employee and TimeEntryType enforce referential integrity

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.