Jeff
Jeff

Reputation: 155

FluentNhibernate Mapping of lookup table in to properties of Parent Object

Using FluentNhiberante is there a way to map the following:

Parent Table (Employee)

EmployeeId INT Primary Key
FirstName
LastName
EmployeeTypeId

Lookup Table (EmployeeType)

EmployeeTypeId INT Primary Key
EmployeeTypeDescription

My class is defined as:

public class Employee
{
    int EmployeeId {get; set;}
    ...
    string EmployeeTypeDescription {get; set;}
}

Is there a way via the FluentNhibernate mapping to populate the EmployeeTypeDescription property in the Employee object from the EmployeeTypeDescription table by looking up using the EmployeeTypeId column in Employee?

I'm pretty sure the normal and proper way to do this is by using References in the mapping file and then by adding a EmployeeType property to the Employee class and accessing the description using Employee.EmployeeType.EmployeeTypeDescription. I'm unable to change the code to do that at this time so am wondering how to just set the EmployeeTypeDescription property for now.

Upvotes: 0

Views: 554

Answers (2)

Firo
Firo

Reputation: 30813

it should be possible tweaking the examplecode below:

public class EmployeeMap : ClassMap<Employee>
{
    public EmployeeMap()
    {
        ...
        Join("EmployeeType", join =>
        {
            join.KeyColumn("EmployeeTypeId");
            join.Map(k => k.TherapieOK, "somecolumn"));
        }
        ...
    }
}

Upvotes: 2

marr75
marr75

Reputation: 5715

You can map the class to a view.

You're correct as far as the normal way to do this.

Upvotes: 0

Related Questions