0

Can you set a default for a composite part in a TPC mapping? I have an entity set class like this:

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;
}

And I mapped this with Fluent NHibernate like this:

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)
}

With this, I must have an id_department column in both the programmer and sales tables, but this column will be the same allways (all sales employees have the same department id). I like to replace the KeyColumn for id_department in both the subclass mappings with a constant, an thus avoid the id_department column in this two tables. This is possible?

Apocatastasis
  • 500
  • 1
  • 9
  • 21

1 Answers1

0

That seems this functionality is supported in Hibernate (Java) but not in NHibernate. fluent nhibernate foreign key with 2 columns mapping

Community
  • 1
  • 1
Apocatastasis
  • 500
  • 1
  • 9
  • 21