您可以在TPC映射中为复合零件设置默认值吗?我有一个像这样的实体集类:
public class Employee()
{
public EmployeeIdentity Id;
public double MonthlySalaryBase;
}
public class EmployeeIdentity()
{
public int DepartmentId;
public int DepartmentEmployeeId;
}
public class SalesEmployee(): Employee
{
public double ComissionRate;
}
public class ProgrammerEmployee(): Employee
{
public int WeeklyExtraHoursAllowed;
}
我用Fluent NHibernate映射了这个:
public class EmployeeMap: ClassMap<Employee>
{
public void Employee()
{
Table("employee");
CompositeId().ComponentCompositeIdentifier<EmployeeIdentity)(x => x.Id).
KeyProperty(x => x.Id.DepartmentId, "id_department").
KeyProperty(x => x.Id.DepartmentEmployeeId, "id_department_employee_id");
Map(x => x.MonthlySalaryBase);
}
}
public class SalesEmployeeMap: SubclassMap<SalesEmployee>
{
Table("sales_employee");
KeyColumn("id_department");
KeyColumn("id_department_employee_id");
Map(x => x.ComissionRate)
}
public class ProgrammerEmployeeMap: SubclassMap<ProgrammerEmployee>
{
Table("programmer_employee");
KeyColumn("id_department");
KeyColumn("id_department_employee_id");
Map(x => x.WeeklyExtraHoursAllowed)
}
有了这个,我必须在程序员和销售表中都有一个id_department列,但是这个列总是相同的(所有销售员工都有相同的部门ID)。我喜欢在子类映射中使用常量替换id_department的KeyColumn,从而避免这两个表中的id_department列。这可能吗?
答案 0 :(得分:0)
似乎Hibernate(Java)支持此功能,但NHibernate不支持。 fluent nhibernate foreign key with 2 columns mapping