使用Fluent API中的额外列映射多对多

时间:2011-11-01 09:34:05

标签: entity-framework ef-code-first

我正在尝试使用代码优先和流畅的api为多对多关系创建映射。我的多对多关系的映射表有一些额外的列。

以下是一些代码示例:

public class SubstanceType
{
   public ICollection<MixConstituent> MixConstituents { get; set }
}

public class MixConstituent
{
   public SubstanceType MixedSubstanceType { get;set;}
   public int Part { get; set; }
   public int Order { get; set; }
}

我的地图会如何?

我试过这个,但没有运气:

class SubstanceTypeConfiguration : BaseConfiguration<SubstanceType>
{
    public SubstanceTypeConfiguration()
        : base("Inventory")
    {
        HasMany(c => c.MixConstituents)
            .WithOptional()
            .Map(c => c.MapKey("SubstanceTypeID"));
    }
}

class MixConstituentConfiguration : BaseConfiguration<MixConstituent>
{
    public MixConstituentConfiguration()
        : base("Inventory")
    {
        HasOptional(c => c.MixedSubstanceType)
            .WithMany()
            .Map(c => c.MapKey("MixedSubstanceTypeID"));
    }
}

0 个答案:

没有答案