π Documentation: IrbyImaging.DomainClasses/Crew.cs
Table of Contents
- Overview & Purpose π
- Dependencies & Technologies π§
- Key Functional Areas π¦
- Data Model:
Crew𧬠- Relationships & Navigation Properties π
- Database Mapping & EF Configuration ποΈ
- UML Diagram π
- Usage Examples & Code Snippets π‘
- Conclusion π―
1. Overview & Purpose π
The Crew class models a work crew within the IrbyImaging domain.
A Crew is a group assigned to a specific job, composed of employees and equipment. This entity provides:
- Identification: Unique
CrewId. - Context: Associates with a
Job. - Composition: Holds collections of employees (
CrewEmployee) and equipment (CrewEquipment). - Auditing: Tracks when and by whom it was created.
- Soft Delete: Marks inactive or removed crews without physical deletion.
This documentation dives deep into how Crew is structured, mapped to the database, and consumed in code.
2. Dependencies & Technologies π§
| Technology / Package | Purpose |
|---|---|
| .NET / C# | Primary language |
| Entity Framework (EF) | ORM mapping via [Table] attribute |
| System.ComponentModel.DataAnnotations.Schema | Data annotations for EF mapping |
| System.Collections.Generic | Collections for navigation properties |
3. Key Functional Areas π¦
- Entity Definition
- Database Mapping
- Audit & Soft-Delete
- Navigation Properties / Relationships
- Default Construction
4. Data Model: Crew π§¬
Class Definition
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace IrbyImaging.DomainClasses
{
[Table("Crew", Schema = "irby")]
public class Crew
{
public Guid CrewId { get; set; }
public string CrewName { get; set; }
public Guid JobId { get; set; }
public virtual Job Job { get; set; }
public string CreatedBy { get; set; }
public DateTime CreatedDate { get; set; }
public bool IsDeleted { get; set; }
// Navigation properties
public virtual ICollection<CrewEmployee> CrewEmployees { get; set; }
= new List<CrewEmployee>();
public virtual ICollection<CrewEquipment> CrewEquipment { get; set; }
= new List<CrewEquipment>();
}
}
Property Reference Table
| Property Name | Type | Description |
|---|---|---|
| CrewId | Guid |
Primary key; unique identifier for each crew. |
| CrewName | string |
Human-readable name of the crew (e.g., βEast Team Alphaβ). |
| JobId | Guid |
Foreign key linking this crew to a Job entity. |
| Job | Job (navigation) |
Virtual link for lazy/eager loading of the related Job. |
| CreatedBy | string |
Username or identifier of the creator. |
| CreatedDate | DateTime |
UTC timestamp of when this crew record was created. |
| IsDeleted | bool |
Soft-delete flag (true = logically deleted). |
| CrewEmployees | ICollection<CrewEmployee> |
Employees assigned to this crew. Defaults to an empty list. |
| CrewEquipment | ICollection<CrewEquipment> |
Equipment allocated to this crew. Defaults to an empty list. |
5. Relationships & Navigation Properties π
@startuml
class Crew {
+Guid CrewId
+string CrewName
+Guid JobId
+string CreatedBy
+DateTime CreatedDate
+bool IsDeleted
}
class Job {
+Guid JobId
+string JobName
...
}
class CrewEmployee {
+Guid CrewEmployeeId
...
}
class CrewEquipment {
+Guid CrewEquipmentId
...
}
Crew "1" -- "1" Job : Job
Crew "1" -- "*" CrewEmployee : CrewEmployees
Crew "1" -- "*" CrewEquipment : CrewEquipment
@enduml
- Crew β Job: Each crew is assigned to exactly one job.
- Crew β CrewEmployee: A crew has many employees.
- Crew β CrewEquipment: A crew has many pieces of equipment.
6. Database Mapping & EF Configuration ποΈ
- Schema:
irby - Table:
Crew - Primary Key:
CrewId - Foreign Key:
JobId
Entity Framework will infer all other mappings (column names match property names).
The [Table("Crew", Schema = "irby")] attribute ensures the class maps to irby.Crew in the database.
7. Usage Examples & Code Snippets π‘
7.1 Creating a New Crew
var newCrew = new Crew
{
CrewId = Guid.NewGuid(),
CrewName = "Alpha Response Team",
JobId = someExistingJobId,
CreatedBy = currentUser.Username,
CreatedDate= DateTime.UtcNow,
IsDeleted = false
};
// Optionally add employees
newCrew.CrewEmployees.Add(new CrewEmployee { /* ... */ });
newCrew.CrewEquipment.Add(new CrewEquipment { /* ... */ });
// Persist via EF DbContext
dbContext.Crews.Add(newCrew);
dbContext.SaveChanges();
7.2 Querying Crews with Includes
// Load crews with related Job, Employees and Equipment
var crews = dbContext.Crews
.Where(c => !c.IsDeleted)
.Include(c => c.Job)
.Include(c => c.CrewEmployees)
.Include(c => c.CrewEquipment)
.ToList();
7.3 Soft-Deleting a Crew
var crew = dbContext.Crews.Find(crewId);
if (crew != null)
{
crew.IsDeleted = true;
dbContext.SaveChanges();
}
8. UML Diagram π
@startuml
package "IrbyImaging.DomainClasses" {
class Crew {
+Guid CrewId
+string CrewName
+Guid JobId
+string CreatedBy
+DateTime CreatedDate
+bool IsDeleted
}
class Job
class CrewEmployee
class CrewEquipment
Crew --> Job
Crew --> "0..*" CrewEmployee
Crew --> "0..*" CrewEquipment
}
@enduml
Paste the above into a PlantUML renderer to visualize the entity relationships.
9. Conclusion π―
The Crew domain class is a pivotal piece of the IrbyImaging domain model, encapsulating:
- Identity & Lifecycle: Uniquely identifiable and audit-tracked.
- Relational Structure: Ties together jobs, employees, and equipment.
- Scalability: Easily extendedβfor example, adding scheduling info or performance metrics.
- Soft Delete Support: Non-destructive removal for historical queries.
With clear property mappings and EF integration, Crew is ready to be consumed throughout services, repositories, and API layers for building robust imaging crew management features.