📖 Documentation: 20240724175502_AddRejectionCommentMechanicTimesheet.Designer.cs

Module
IrbyImaging.DbContext/Migrations
Generated
July 24, 2024 – 17:55:02
Purpose
Snapshot of the EF Core model after the AddRejectionCommentMechanicTimesheet migration.


🗂 Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. EF Core Migrations Anatomy
  5. Data Model Snapshot
  6. Relationships & Indexes
  7. How to Apply & Use This Migration
  8. Sample Code & CLI Commands
  9. UML Diagram (Mermaid)
  10. Conclusion

1. Overview & Purpose

The Designer file is an auto‑generated snapshot of your Entity Framework Core model after running the migration AddRejectionCommentMechanicTimesheet. It is not hand‑edited; EF Core uses it to understand how to transition from one model state to another.

  • It contains the BuildTargetModel(ModelBuilder modelBuilder) method, which defines:
    • Tables, columns, types, keys, indexes.
    • Relationships (foreign keys, navigations).
    • Inheritance via TPH (Table‑per‑Hierarchy).
  • Key change: The MechanicTimesheet entity now has a new column/property:
    b.Property<string>("RejectionComment")
     .HasColumnType("nvarchar(max)");
    

2. Key Functional Areas

  • 🛠 Model Snapshot
    Captures the entire domain model at this migration point.
  • 📑 Schema Definition
    Maps CLR classes to tables, columns, data types, constraints.
  • 🔗 Relationships
    Configures FK constraints and navigation properties.
  • 📊 Indexes & Keys
    Ensures efficient lookups (e.g., unique indexes, composite keys).
  • 🌐 Inheritance
    Implements TPH for Asset and its subtypes (Computer, MobileDevice, etc.).

3. Dependencies & Technologies

Technology Version/Notes
.NET / C# 7.x / EF Core 7.0.7
Microsoft.EntityFrameworkCore Core ORM for mapping domain → relational
Microsoft.EntityFrameworkCore.SqlServer SQL Server provider
EF Core Migrations Tracks incremental Up() / Down() changes

4. EF Core Migrations Anatomy

4.1. Migration Class vs. Designer File

  • Migration Class (20240724175502_AddRejectionCommentMechanicTimesheet.cs)

    • Contains Up() and Down() methods.
    • Adds/removes the RejectionComment column in the MechanicTimesheet table.
  • Designer File (...Designer.cs)

    • Contains a full model snapshot via BuildTargetModel.
    • EF Core uses this to compare before/ after states when scaffolding future migrations.

4.2. BuildTargetModel Method

protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
    #pragma warning disable 612, 618
    modelBuilder
        .HasAnnotation("ProductVersion", "7.0.7")
        .HasAnnotation("Relational:MaxIdentifierLength", 128);

    SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
    
    // ... thousands of lines defining Entities, Properties, Keys, Indexes ...
}
  • Annotations:

    • .HasAnnotation("ProductVersion", "...") records EF Core version.
    • .UseIdentityColumns() configures identity PK by default.
  • Entity Definitions:
    Each .Entity("Namespace.ClassName", b => { ... }) block defines one table.


5. Data Model Snapshot

Note: Over 80 domain classes are configured. Below is a representative sample.

5.1. Global Annotations & Conventions

  • Schema: Default schema is "irby" for most tables.
  • Identifier Length: Max 128 chars for SQL identifiers.
  • Identity: SQL Server identity columns for integer PKs.

5.2. Selected Entities & Tables

Entity Class Table Name Schema Key Notes
IrbyImaging.DomainClasses.Asset Asset irby Id : uniqueidentifier Base for TPH inheritance.
MechanicTimesheet MechanicTimesheet irby Id : uniqueidentifier Focus entity.
AssetModel AssetModel irby Id : int Cascade FK to MakeId.
Employee Employee irby EmployeeId : uniqueidentifier Unique index on JdeNumber.
WorkOrder WorkOrder irby WorkOrderId : uniqueidentifier FK to Job.
Job Job irby JobId : uniqueidentifier Unique index on JdeNumber.
… 70+ more
  • AssetHistory
  • BillingInvoice
  • CarrierType / CarrierTypeDetail
  • CovidTestData
  • Customer, Department, DirectorLeaseInfo, DirectorProperties
  • DocumentAttribute, DocumentCategory, DocumentImage, DocumentType
  • Equipment, EquipmentType, EquipmentClass
  • FieldOffice, GeneralLedger, GLTypeDetail
  • LinkRolePermission, LinkUserRole, Role, Permissions
  • PurchaseOrder, RequestOption, Ticket, Update
  • TimeSheetEntry, TimeEntryType, WIP, WorkOrder, etc.

5.3. MechanicTimesheet: New RejectionComment

modelBuilder.Entity("IrbyImaging.DomainClasses.MechanicTimesheet", b =>
{
    b.ToTable("MechanicTimesheet", "irby");

    b.Property<Guid>("Id")
     .ValueGeneratedOnAdd()
     .HasColumnType("uniqueidentifier");

    // ... other existing properties ...
    b.Property<string>("RejectionComment") // <-- ADDED by this migration
     .HasColumnType("nvarchar(max)");

    b.HasKey("Id");
});
  • Before:
    MechanicTimesheet had columns like StartDate, EmployeeId, Status, etc.
  • After:
    A free‑text RejectionComment to capture supervisor feedback on rejected timesheets.

6. Relationships & Indexes

  • Foreign Keys:
    • E.g. MechanicTimesheet → Employee (via EmployeeId, cascades on delete?).
  • Indexes:
    • Many unique indexes on business keys (JdeNumber, Imei, etc.).
    • Composite keys where needed.

Example:

b.HasIndex("EmployeeId");
b.HasIndex("TimeEntryTypeId");

b.HasOne("IrbyImaging.DomainClasses.Employee", "Employee")
 .WithMany()
 .HasForeignKey("EmployeeId")
 .OnDelete(DeleteBehavior.Cascade)
 .IsRequired();

7. How to Apply & Use This Migration

  1. Add Migration
    dotnet ef migrations add AddRejectionCommentMechanicTimesheet
    
  2. Review/Customize
    • Check the generated Up() and Down() in
      20240724175502_AddRejectionCommentMechanicTimesheet.cs.
  3. Update Database
    dotnet ef database update
    
  4. Verify
    • In SQL Server:
      SELECT TOP 1 RejectionComment
      FROM irby.MechanicTimesheet;
      

8. Sample Code & CLI Commands

# List pending migrations
dotnet ef migrations list

# Script SQL for this migration
dotnet ef migrations script 20240724175502_AddRejectionCommentMechanicTimesheet

# Apply only this migration
dotnet ef database update 20240724175502_AddRejectionCommentMechanicTimesheet

9. UML Diagram (Mermaid)

classDiagram
    class MechanicTimesheet {
      +Guid Id
      +DateTime StartDate
      +string StartTime
      +string EndTime
      +string RegularTime
      +string OverTime
      +string PayCode
      +string CostType
      +string Job
      +string WorkOrder
      +string UnitNumber
      +string SubmittedBy
      +int Status
      +string Description
      +Guid EmployeeId
      +string EmployeeName
      +string RejectionComment       <-- NEW
    }
    class Employee {
      +Guid EmployeeId
      +string FirstName
      +string LastName
      +string Status
      +string JdeNumber
    }
    MechanicTimesheet "1" --> "1" Employee : EmployeeId

10. Conclusion

🔹 20240724175502_AddRejectionCommentMechanicTimesheet.Designer.cs is a critical EF Core snapshot capturing your entire domain model after the addition of the RejectionComment column on the MechanicTimesheet table.

🔹 It ensures consistency of the model when generating future migrations, providing EF Core with the “target” shape of your database.

🔹 Tip: Always review both the migration (Up/Down) and the designer snapshot to fully understand how your schema evolves over time.

Feel free to explore the other entities and navigation configurations in this file to get a comprehensive view of your current schema! 🎉