如果我有
two aggregates
第一次聚合:
数据澄清:
工作时间规定:
public class WorkTimeRegulation : Entity<Guid>, IAggregateRoot
{
private WorkTimeRegulation()//COMB
: base(Provider.Sql.Create()) // required for EF
{
}
private WorkTimeRegulation(Guid id) : base(id)
{
_assignedWorkingTimes = new List<WorkingTime>();
_enrolledParties = new List<RegulationEnrolment>();
}
private readonly List<WorkingTime> _assignedWorkingTimes;
private readonly List<RegulationEnrolment> _enrolledParties;
public string Name { get; private set; }
public byte NumberOfAvailableRotations { get; private set; }
public bool IsActive { get; private set; }
public virtual IEnumerable<WorkingTime> AssignedWorkingTimes { get => _assignedWorkingTimes; }
public virtual IEnumerable<RegulationEnrolment> EnrolledParties { get => _enrolledParties; }
//...
}
Id| Name | NumberOfAvailableRotations| IsActive
1| General Rule | 2 | true
工作时间:
public class WorkTime : Entity<Guid>
{
private WorkTime()
: base(Provider.Sql.Create()) // required for EF
{
}
private WorkTime(Guid id) : base(id)
{
ActivatedWorkingTimes = new List<WorkingTimeActivation>();
}
private ICollection<WorkingTimeActivation> _activatedWorkingTimes;
public string Name { get; set; }
public byte NumberOfHours { get; set; }
public byte NumberOfShortDays { get; set; }
public Guid WorkTimeRegulationId { get; private set; }
public virtual ICollection<WorkingTimeActivation> ActivatedWorkingTimes { get => _activatedWorkingTimes; private set => _activatedWorkingTimes = value; }
//....
}
Id| Name | NumberOfHours| NumberOfShortDays |WorkTimeRegulationId
1 | Winter | 8 | 1 | 1
2 | Summer | 6 | 0 | 1
第二个聚合:
数据澄清:
public class Shift : Entity<Guid>, IAggregateRoot
{
private readonly List<ShiftDetail> _assignedShiftDetails;
private readonly List<ShiftEnrolment> _enrolledParties;
public string Name { get; set; }
public ShiftType ShiftType { get; set; }
public int WorkTimeRegulationId { get; set; }
public bool IsDefault { get; set; }
public virtual WorkingTimeRegulation WorkTimeRegulation { get; set; }
public virtual IEnumerable<ShiftDetail> AssignedShiftDetails { get => _assignedShiftDetails; }
public virtual IEnumerable<ShiftEnrolment> EnrolledParties { get => _enrolledParties; }
//...........
}
Id| Name | ShiftType | WorkTimeRegulationId | IsDefault
1 | IT shift | Morning | 1 | 1
移位详细信息:
public class ShiftDetail : Entity<Guid>
{
public Guid ShiftId { get; private set; }
public Guid WorkTimeId { get; private set; }
public DateTimeRange ShiftTimeRange { get; private set; }
public TimeSpan GracePeriodStart { get; private set; }
public TimeSpan GracePeriodEnd { get; private set; }
public virtual WorkTime WorkTime { get; private set; }
private ShiftDetail()
: base(Provider.Sql.Create()) // required for EF
{
}
//..........
}
ShiftId WorkTimeId shift-start shift-end
1 1 08:00 16:00
1 2 08:00 14:00
我的问题是:
-
ShiftDetail
)保存参考文献
对于另一个非聚合根(
WorkTime
-
领域专家澄清:要创建一个有效的移位,那么我们
应该有一个
shift detail
为每一个
worktime
与
worktimeRegulation
. 无法更新中的工作小时数
工作时间
shiftDetails
. 前面的例子表明
有
two worktimes(winter,summer)
,所以我们有一个
shiftdetai
l代表
winter
坚持
8
shiftdetail
对于
summer
坚持
6
工作时间
)如何强制这个不变量?
-
根据前面的信息,我是否犯了与骨料规格相关的错误?