Lets say I have a class Foo like the following:
public class Foo
{
public virtual int FooId { get; protected internal set; }
public virtual List<Bar> bars { get; protected internal set;}
public virtual Bar DefaultBar { get; set; }
}
Where Foo has a collection of Bar and has a property DefaultBar of type Bar.
The collection of bars is stored in a table with the following fields
FooBarID int PK
FooID int FK
BarID int FK
Default bit
Where only one row for a collection of matching FooID values can have a Default=1. Ignoring this poor design (needed by legacy system),
In my map I have the following:
<class name="Bar">
<id name="BarID" generator="native" unsaved-value="0" />
</class>
<class name="Foo">
<id name="FooID" generator="native" unsaved-value="0" />
<set name="Bars"
table="FooBars">
<key column="FooId" />
<many-to-many class="Bar" column="BarId" />
</set>
</class>
How would I map the value indicated by BarID in the single matching row with Default=1 to the DefaultBar property of the Foo instance?