我正在使用 Fluent NHibernate 1.1.1.694,它使用的语法与 FNH1.0 略有不同,尤其是在字典映射方面。
在我的模型中,我有员工、地址和地址类型(邮政、物理等)。
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; }
}
我的映射:
public class EmployeeMap : ClassMap
{
public EmployeeMap()
{
CompositeId()
.KeyProperty(e => e.IdentityType)
.KeyProperty(e => e.IdentityValue);
// <snip other properties />
HasManyToMany(e => e.Addresses)
.Inverse();
}
}
生成以下 .hbm.xml 片段:
<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>
我想生成的 .hbm.xml是
<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>
显然这会失败,因为我没有告诉它有一个复合 ID 可用于父键。但我找不到告诉它的方法。.HasManyToMany<Key,Value>() 的 .Columns 和 .ParentKeyColumns 不存在
我应该如何映射这个?