📚 Documentation: 20241115170848_FieldLogEmployees.Designer.cs


🗂️ Table of Contents

  1. Overview & Purpose
  2. Migration Class Structure
  3. BuildTargetModel Method
  4. New Entity: FieldLogEmployees 📋
  5. Entity & Relationship Summary
  6. Dependencies & Technologies 🔗
  7. Using the Migration in EF Core 🚀
  8. Sample Commands & Code Snippets
  9. Conclusion & Next Steps

1. Overview & Purpose

This file is an auto‐generated Entity Framework Core designer class for the migration:

[MIGRATION ID] 20241115170848_FieldLogEmployees
  • 📌 Purpose:
    • Defines the target database model after applying the FieldLogEmployees migration.
    • Used internally by EF Core to compare the existing schema to the new model and generate SQL scripts.
  • ⚠️ Note:
    • Do not modify manually. All changes should be made to your DbContext or entity classes, then scaffolded via dotnet ef migrations add.

2. Migration Class Structure

namespace IrbyImaging.DbContext.Migrations
{
    [DbContext(typeof(IrbyContext))]
    [Migration("20241115170848_FieldLogEmployees")]
    partial class FieldLogEmployees
    {
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
            // Model snapshot code...
        }
    }
}
  • Attributes
    • [DbContext(typeof(IrbyContext))]: Indicates which DbContext this migration targets.
    • [Migration("20241115170848_FieldLogEmployees")]: Unique identifier & name of the migration.
  • Partial class: Combines with the accompanying .cs file (not shown) that contains Up()/Down() methods for schema changes.

3. 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);

    // ... Entities definitions follow ...
    #pragma warning restore 612, 618
}
  • Responsibilities
    1. Annotations
      • EF version, naming conventions, SQL Server identity column strategy.
    2. Entity Definitions
      • Defines every mapped DbSet in the IrbyContext.
      • Establishes properties, keys, column types, indexes, relationships, and table names.
  • Why it matters
    • Ensures consistent snapshot of your model at this point in time, enabling EF to generate proper Up()/Down() operations.

4. New Entity: FieldLogEmployees 📋

This migration introduces or updates the FieldLogEmployees table in the irby schema:

Column CLR Type SQL Type Notes
FieldLogId Guid uniqueidentifier Primary Key (auto‐generated)
CreatedOn DateTime datetime2 When record was created.
CreatedBy string nvarchar(max) User who created the entry.
UpdatedOn DateTime datetime2 When record was last updated.
UpdatedBy string nvarchar(max) User who last modified it.
ReviewedOn DateTime datetime2 When reviewed by foreman/supervisor.
ReviewedBy string nvarchar(max) Who performed the review.
ApprovedOn DateTime datetime2 When timesheet/field log was approved.
ApprovedBy string nvarchar(max) Who approved it.
WorkDate DateTime datetime2 Date of field work.
JobNumber string nvarchar(max) Associated job number.
CrewId string nvarchar(max) Crew identifier.
EmployeeId string nvarchar(max) Worker’s employee ID.
EmployeeName string nvarchar(max) Worker’s name (redundant).
Hours string nvarchar(max) Hours worked.
StartTime string nvarchar(max) Shift start time.
StopTime string nvarchar(max) Shift end time.
PerDiemRate string nvarchar(max) Daily allowance rate.
BreakfastProvided bool bit Meal flags…
LunchProvided bool bit …
DinnerProvided bool bit …
MotelProvided bool bit …
WorkCostCode string nvarchar(max) Billing cost code.
WorkOrderNumber string nvarchar(max) External work order reference.
ForemanSignature string nvarchar(max) Signature (image/base64).
modelBuilder.Entity("IrbyImaging.DomainClasses.FieldLogEmployees", b =>
{
    b.Property<Guid>("FieldLogId")
        .ValueGeneratedOnAdd()
        .HasColumnType("uniqueidentifier");
    // … all other properties …
    b.HasKey("FieldLogId");
    b.ToTable("FieldLogEmployees", "irby");
});

5. Entity & Relationship Summary

Note: The BuildTargetModel method defines over 100 entities. Below is a high‑level categorization:

Category Sample Entities
Financial AccountBalances, AccountLedger, BillingInvoice, GeneralLedger, WIP
Asset Management Asset, AssetHistory, AssetModel, Manufacturer, Computer, SafetyEquipment
Human Resources Employee, Department, Role, LinkUserRole, LinkRolePermission, TimeSheetEntry
Document Imaging DocumentImage, DocumentType, DocumentCategory, TempDocumentData, BlobData
Field Operations FieldLogEmployees, FieldOffice, Job, WorkOrder, MechanicTimesheet
Audit & Security AuditDetail, Permissions, LinkRolePermission, Ticket, Update
External Sync (ODS) ODSCustomer, ODSEmployee, ODSJob

Relationships:

  • One‑to‑Many: e.g., Job → Employees, FieldOffice → Jobs, Employee → Assets.
  • Many‑to‑Many via link tables: Employee ⟷ Role (LinkUserRole), Role ⟷ Permission (LinkRolePermission).
  • Table‑Per‐Hierarchy (TPH) for Asset subtypes (Computer, DeskPhone, MobileDevice, etc.).

6. Dependencies & Technologies 🔗

  • .NET Version: Targeting EF Core 7.0.7
  • Database Provider: SQL Server (uses UseIdentityColumns)
  • ORM: Entity Framework Core
  • Language: C# 10+, Nullability disabled (#nullable disable)
  • Schema: Default schema named irby for most tables

7. Using the Migration in EF Core 🚀

  1. Add Migration
    dotnet ef migrations add FieldLogEmployees
    
  2. Apply Migration
    dotnet ef database update
    
  3. Inspect Generated SQL
    dotnet ef migrations script 20241115170848_FieldLogEmployees
    

8. Sample Commands & Code Snippets

  • Querying Field Log Entries

    using var context = new IrbyContext();
    var logs = context.Set<FieldLogEmployees>()
        .Where(f => f.ApprovedOn > DateTime.UtcNow.AddDays(-7))
        .OrderByDescending(f => f.WorkDate)
        .ToList();
    
  • Inserting a New Field Log

    var entry = new FieldLogEmployees
    {
        CreatedOn = DateTime.UtcNow,
        CreatedBy = "jane.doe",
        WorkDate   = DateTime.Today,
        JobNumber  = "JOB-1234",
        EmployeeId = "EMP001",
        EmployeeName = "John Doe",
        Hours      = "8",
        StartTime  = "08:00",
        StopTime   = "16:00",
        LunchProvided = true,
        WorkCostCode  = "CC-456",
        // …
    };
    context.Add(entry);
    context.SaveChanges();
    

9. Conclusion & Next Steps

  • ✅ This designer snapshot is crucial for EF Core to track and apply schema changes consistently.
  • 🔄 Do not edit this file directly—update your domain model and re‐scaffold migrations.
  • 📈 Next Steps:
    1. Review your domain classes in IrbyImaging.DomainClasses.
    2. Ensure new properties or tables are correctly modeled.
    3. Run dotnet ef migrations add and update as needed.

Happy Coding! 🚀