This is an example based on the pretty clear example in documentation: 23.2. Author/Work
<class name="A" table="A" >
<id name="Id" column="A_Id" generator="native" />
<bag name="Bs" table="AB" lazy="true">
<key column="A_Id">
<many-to-many class="B" column="B_Id" not-null="true" />
</bag>
...
</class>
<class name="B" table="B" >
<id name="Id" column="B_Id" generator="native" />
<bag name="As" table="AB" lazy="true" inverse="true">
<key column="B_Id">
<many-to-many class="A" column="A_Id" not-null="true" />
</bag>
...
</class>
And this would be the classes in C#
public class A
{
public virtual int Id { get; set; }
public virtual IList<B> Bs { get; set; }
}
public class B
{
public virtual int Id { get; set; }
public virtual IList<A> As { get; set; }
}
The table AB is here implicitly mapped ... no explicit pairing object AB
But my own prefered way is to Extend table AB with AB_ID surrogated key, and map it as a standard object. If you like read more about explicit pairing object as a mapped Entity:
UPDATE related to the comment that B can have only one A
In that case, we do not need the AB table. The B should have the column A_Id, expressing the rela reference:
<class name="A" table="A" >
<id name="Id" column="A_Id" generator="native" />
<bag name="Bs" table="B" lazy="true">
<key column="A_Id">
<!-- not MANY but ONE-TO-Many -->
<one-to-many class="B" />
</bag>
...
</class>
<class name="B" table="B" >
<id name="Id" column="B_Id" generator="native" />
<many-to-one name="A" column="A_Id" />
...
</class>
The entities
// This class is the same
public class A
{
public virtual int Id { get; set; }
public virtual IList<B> Bs { get; set; }
}
// here just a reference
public class B
{
public virtual int Id { get; set; }
public virtual A A { get; set; }
}
The thing is, either it is many-to-many
and the table AB is in place - or not. Nothing in between I'd say