In our app we have a Ship object and a ship can be assigned Jobs. Each Job has a WorkRole that describes the work the Ship is doing.
Here are my classes:
public class Job
{
public string ShipId { get; set; }
public IWorkRole WorkRole { get; set; }
public DateTimeOffset Start { get; set; }
public DateTimeOffset End{ get; set; }
}
public class Ship
{
public string Id { get; set; }
public string Name { get; set; }
}
public interface IWorkRole
{
string Comments { get; set; }
}
public class RigMoveWorkRole : IWorkRole
{
public string Comments { get; set; }
public string RigId { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
}
There can be many different types of WorkRole each with different properties.
I would like to be able to query a Ships Jobs by its WorkRole. So for example query all Jobs for a Ship that did a RigMoveWorkRole.
Is this approach a good way to model this as im not sure if querying by an Objects type is a good solution, although it can be done with RavenDB. I thought about embedding an Enum in each WorkRole so i could easily query using that, for example:
public interface IWorkRole
{
WorkRoleType WorkRoleType { get; }
string Comments { get; }
}
public abstract class WorkRoleBase : IWorkRole
{
public WorkRoleType WorkRoleType { get; private set; }
public string Comments { get; protected set; }
protected WorkRoleBase(WorkRoleType type)
{
WorkRoleType = type;
}
}
public class AllDutiesWorkRole : WorkRoleBase
{
public AllDutiesWorkRole(string comments) : base(WorkRoleType.AllDuties)
{
Comments = comments;
}
}
public class RigMoveWokRole : WorkRoleBase
{
public string RigId { get; private set; }
public RigMoveWokRole(string rigId, string comments) : base(WorkRoleType.RigMove)
{
RigId = rigId;
Comments = comments;
}
}
public enum WorkRoleType
{
RigMove,
AllDuties
}
This way i could just query the IWorkRole.WorkRoleType interface property on the Job class:
Session.Query<Job>().Where(x => x.WorkRole.WorkRoleType == WorkRoleType.RigMove);
Can anyone see any problems with this model or have any suggestions for a better way to do it ?
Thanks !