我想要一个'UnassignedDepartment'对象,而不是让员工有一个空部门:
public class UnassignedDepartment : Department
{
public UnassignedDepartment() : base("not yet assigned") {
Id = -99; <-- just some Id that can be held constant, not be generated..
}
}
可以通过Department类中的静态便捷字段访问:
public class Department : Entity
{
public static readonly Department UNASSIGNED = new UnassignedDepartment();
....
}
我正在使用S#rpArch的框架作为基本实体,混合使用FNH自动化,覆盖&amp; amp;约定。从持久性的角度来看,将其与具有“特殊”ID的其他部门保持一致似乎是合乎逻辑的,但我不知道如何正确地做到这一点。请赐教!
Thx,Berryl
答案 0 :(得分:2)
我不明白你想要完成什么,但也许这会有所帮助。将Department映射为Employee中的私有字段,如果为null,则返回UnassignedDepartment。
private Department _department; // map this in FNH
public Department Department
{
get { return _department ?? _department.UNASSIGNED; }
}