I'm using Fluent NHibernate 1.1.1.694 which uses a slightly different syntax than FNH1.0, especially when it comes to dictionary mapping.
In my model, I have Employees, Addresses and AddressTypes (postal, physical, etc).
public class Employee
{
// <snip other properties />
public virtual IDictionary Addresses { get; set; }
public Employee()
{
this.Addresses = new Dictionary();
}
}
public enum AddressType
{
Physical,
Postal
}
public class Address
{
public virtual int Id { get; private set; }
public virtual IList Lines { get; set; }
public virtual string City { get; set; }
public virtual string Zip { get; set; }
}
My mappings:
public class EmployeeMap : ClassMap
{
public EmployeeMap()
{
CompositeId()
.KeyProperty(e => e.IdentityType)
.KeyProperty(e => e.IdentityValue);
// <snip other properties />
HasManyToMany(e => e.Addresses)
.Inverse();
}
}
The following .hbm.xml snippet is generated:
<map inverse="true" name="Addresses" table="EmployeeAddresses" mutable="true">
<key>
<column name="Employee_id" />
</key>
<index type="Domain.Entities.AddressType, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Key" />
</index>
<many-to-many class="Domain.Entities.Address, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Address_id" />
</many-to-many>
</map>
The .hbm.xml that I'd like to generate is
<map inverse="true" name="Addresses" table="EmployeeAddresses" mutable="true">
<key>
<column name="IdentityType" />
<column name="IdentityValue" />
</key>
<index type="Domain.Entities.AddressType, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Key" />
</index>
<many-to-many class="Domain.Entities.Address, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Address_id" />
</many-to-many>
</map>
Obviously this will fail, because nowhere am I telling it that there is a composite ID to use for the parent key. But I can't find the methods to tell it. The .Columns and .ParentKeyColumns don't exist for .HasManyToMany<Key,Value>()
How should I map this?