0

I'm trying to map two classes together via a N:N relationship, and that's working fine as is. However, there's a field in my join table that I'd like to also map to a property on the child object, and I haven't an inkling on how to do that.

Basically, I have my map done something like:

CompanyMap : ClassMap<Company> {
    public CompanyMap() {
        HasManyToMany<Employee>(x => x.Employees)
            .Table("COMPANY_EMPLOYEE")
            .ParentKeyColumn("COMPANY_ID")
            .ChildKeyColumn("EMPLOYEE_ID")
            ;
    }
}

with my Employee class having a .Tenure property.

The value of that tenure is specified in my COMPANY_EMPLOYEE join table, with the following schema:

COMPANY_ID  |  EMPLOYEE_ID  |  TENURE

I don't know if this is something embarassingly simple, or something downright impossible to do, but if someone can point me in the right direction, I'd really appreciate it.

Thanks!

Richard Neil Ilagan
  • 14,627
  • 5
  • 48
  • 66

1 Answers1

2

You need to create a CompanyEmployee object in your domain model and map both relationships to it as one-to-many. That is, Company has a collection of CompanyEmployee and Employee has a collection of CompanyEmployee.

Jamie Ide
  • 48,427
  • 16
  • 81
  • 117