Here is the scenario. I have two classes, say Husband and Wife :D And the relation between these two classes are defined through a third intermediate table named People.
classes:
class Husband
{
public virtual int HusbandId { get; set; }
public virtual Wife Wife { get; set; }
}
class Wife
{
public virtual int WifeId { get; set; }
...
}
Tables:
Husband :: Table
HusbandId : int
Wife :: Table
WifeId : int
People :: Table
PeopleId : int
ManId : int
WomanId : int
RelationType : int
In the People table, RelationType = 1 indicates a marriage relation between a man and a woman where ManId == HusbandId and WomanId == WifeId.
Note that it is guaranteed that there is only one Wife for each Husband in People table. Also it is needless to say that I cannot modify the tables. It is legacy database.
Mapping:
class HusbandMap : ClassMapping<Husband>
{
public HusbandMap()
{
Id(x => x.HusbandId);
ManyToOne(x => x.Wife); // <-- How to make this mapping work ?
}
}
class WifeMap : ClassMapping<Wife>
{
public WifeMap()
{
Id(x => x.WifeId);
}
}
Now the question is how I can have a many-to-one mapping from Husband to Wife using the intermediate table People?