0

您可以为 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 列。这个有可能?

4

1 回答 1

0

这似乎在 Hibernate (Java) 中支持此功能,但在 NHibernate 中不支持。具有 2 列映射的流利的 nhibernate 外键

于 2013-08-16T19:27:44.417 回答