流利的NHibernate HasManyToMany()IDictionary<>复合ID问题

时间:2011-02-15 09:24:15

标签: fluent-nhibernate many-to-many idictionary composite-id

我正在使用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&lt; Key,Value&gt;()

不存在.Columns和.ParentKeyColumns

我该如何映射?

0 个答案:

没有答案