CrewEquipment Entity Documentation 🛠️


Table of Contents 📑

  1. Overview & Purpose
  2. Domain Model
  3. Key Functional Areas
  4. Dependencies & Technologies
  5. View Models & Data Models
  6. Entity Framework Core Configuration
  7. Helper Methods & Utilities
  8. Error Handling & Return Types
  9. API Endpoints Overview
  10. Third-party Integrations
  11. Sample Code Blocks & Usage Examples
  12. UML Diagram
  13. Conclusion

1. Overview & Purpose 🎯

CrewEquipment is an Entity Framework Core (EF Core) data model representing the assignment of a specific piece of Equipment to a Crew for a particular Job, potentially tied to a CostCode. It captures operational metadata such as worked hours, creation audit info, and soft‑deletion status.

Use cases include:

  • Tracking which crew operates which equipment on a job.
  • Recording time spent by equipment (WorkedHours).
  • Associating cost codes for billing and reporting.
  • Auditing creation metadata for traceability.

2. Domain Model 📦

In the IrbyImaging.DomainClasses namespace, the CrewEquipment class ties together four core concepts:

  • Crew: The team or personnel operating equipment.
  • Equipment: Machinery or tools assigned to a crew.
  • Job: The project or work order under which the assignment falls.
  • CostCode: (Optional) Financial code for cost-tracking.

This entity facilitates many-to-many (via multiple relationships) and one-to-many navigation properties, enforcing referential integrity and enabling eager/lazy loading via EF Core.


3. Key Functional Areas 🔑

  • Assignment Tracking
    Associates Crew + Equipment + Job.
  • Time Logging
    WorkedHours (nullable decimal) captures usage duration.
  • Cost Allocation
    Optional CostCode guides billing and accounting.
  • Audit & Soft‑Delete
    • CreatedBy & CreatedDate for audit trails.
    • IsDeleted flag for soft‑deletion.

4. Dependencies & Technologies 🔗

  • Language: C# 10.0
  • Runtime: .NET 6.0 / .NET 7.0 (or later)
  • ORM: Microsoft.EntityFrameworkCore (EF Core)
  • Data Annotations:
    • [Key], [Required], [Table]
    • DeleteBehavior.Restrict for FK cascade control
  • Namespace: IrbyImaging.DomainClasses

5. View Models & Data Models 📋

View Models

N/A – This file is strictly a Domain/Data Model. No view models are defined here.

Data Model: Properties & Relationships

Property Type Required? Description
CrewEquipmentId Guid Yes Primary key (auto‐generated via Guid.NewGuid()).
CrewId Guid Yes FK → Crew.CrewId.
Crew Crew Yes Navigation property; restrict delete if referenced.
EquipmentId Guid Yes FK → Equipment.EquipmentId.
Equipment Equipment Yes Navigation property; restrict delete if referenced.
JobId Guid Yes FK → Job.JobId.
Job Job Yes Navigation property; restrict delete if referenced.
CostCodeId Guid? No FK → CostCode.CostCodeId (optional).
CostCode CostCode? No Navigation property; restrict delete if referenced.
WorkedHours decimal? No Hours worked by the equipment for this assignment (nullable).
CreatedBy string Yes Username or identifier who created the record.
CreatedDate DateTime Yes UTC timestamp when the record was created.
IsDeleted bool Yes Soft-delete flag.

6. Entity Framework Core Configuration 🚧

The CrewEquipment class uses Data Annotations to configure EF Core mapping:

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace IrbyImaging.DomainClasses
{
    [Table("CrewEquipment", Schema = "irby")]
    public class CrewEquipment
    {
        [Key]
        public Guid CrewEquipmentId { get; set; } = Guid.NewGuid();

        [Required]
        public Guid CrewId { get; set; }

        [DeleteBehavior(DeleteBehavior.Restrict)]
        public virtual Crew Crew { get; set; }

        [Required]
        public Guid EquipmentId { get; set; }

        [DeleteBehavior(DeleteBehavior.Restrict)]
        public virtual Equipment Equipment { get; set; }

        [Required]
        public Guid JobId { get; set; }

        [DeleteBehavior(DeleteBehavior.Restrict)]
        public virtual Job Job { get; set; }

        public Guid? CostCodeId { get; set; }

        [DeleteBehavior(DeleteBehavior.Restrict)]
        public CostCode? CostCode { get; set; }

        public decimal? WorkedHours { get; set; }

        public string CreatedBy { get; set; }

        public DateTime CreatedDate { get; set; }

        public bool IsDeleted { get; set; }
    }
}

Key Notes:

  • Restrict delete behavior prevents cascading deletes, ensuring historical records are retained.
  • The default schema is set to irby; adjust in OnModelCreating if necessary.

7. Helper Methods & Utilities 🧰

N/A – This class defines pure data properties; no helper methods are included here.


8. Error Handling & Return Types ⚠️

N/A – This is an EF Core entity; error handling occurs at the repository/service layer.


9. API Endpoints Overview 🌐

N/A – No direct API controllers in this file.
See your Web API project for endpoints managing CrewEquipment.


10. Third-party Integrations 🔌

None.
This entity relies solely on EF Core and standard .NET libraries.


11. Sample Code Blocks & Usage Examples 💻

Adding a New CrewEquipment

using var context = new IrbyImagingDbContext();

// Prepare the entity
var assignment = new CrewEquipment
{
    CrewId       = existingCrew.CrewId,
    EquipmentId  = existingEquipment.EquipmentId,
    JobId        = existingJob.JobId,
    CostCodeId   = optionalCostCode?.CostCodeId,
    WorkedHours  = 7.5m,
    CreatedBy    = "jdoe",
    CreatedDate  = DateTime.UtcNow,
    IsDeleted    = false
};

// Persist to database
context.CrewEquipment.Add(assignment);
context.SaveChanges();

Querying Assignments for a Job

var assignments = context.CrewEquipment
    .Include(ce => ce.Crew)
    .Include(ce => ce.Equipment)
    .Where(ce => ce.JobId == targetJobId && !ce.IsDeleted)
    .OrderBy(ce => ce.CreatedDate)
    .ToList();

foreach (var ce in assignments)
{
    Console.WriteLine($"{ce.Crew.Name} used {ce.Equipment.Name} for {ce.WorkedHours}h");
}

12. UML Diagram 📊

classDiagram
    direction LR
    class CrewEquipment {
        +Guid CrewEquipmentId
        +Guid CrewId
        +Guid EquipmentId
        +Guid JobId
        +Guid? CostCodeId
        +decimal? WorkedHours
        +string CreatedBy
        +DateTime CreatedDate
        +bool IsDeleted
    }
    CrewEquipment "1" -- "1" Crew : [CrewId]
    CrewEquipment "1" -- "1" Equipment : [EquipmentId]
    CrewEquipment "1" -- "1" Job : [JobId]
    CrewEquipment "1" -- "0..1" CostCode : [CostCodeId]

13. Conclusion 🏁

The CrewEquipment entity serves as a central junction in the IrbyImaging domain, linking crews, equipment, and jobs along with auditing and costing information. It is designed for EF Core with strong referential integrity and soft‑delete support, making it robust for real‑world operations tracking and financial reporting. Integrate it into your repository or service layer to perform CRUD operations and reporting as shown in the usage examples above.

Feel free to explore related entities—Crew, Equipment, Job, and CostCode—for a full picture of the domain model.


© 2023 IrbyImaging – Domain Model Documentation