EF6 Fluent API映射到复合键

时间:2013-12-09 04:20:46

标签: asp.net-mvc entity-framework-5

在下面的代码中,我试图告诉Code First,SupplyPointServiceSubscriptions将容纳2个外键。一个到SupplyPoint,一个到SupplyPointService。

我在*

处遇到错误

// e.SupplyPoint下的蓝线,错误:         //错误3'AscendancyCF.Models.SupplyPointServiceSubscription'         //不包含'SupplyPoint'的定义         //并且没有扩展方法'SupplyPoint'接受第一个参数         //输入'AscendancyCF.Models.SupplyPointServiceSubscr .....

public class SupplyPointServiceSubscription
{
    [Key]
    int SupplyPointServiceSubscriptionId { get; set; }
    int? SupplyPointId { get; set; }
    int? SupplyPointServiceId { get; set; }
    DateTime SupplyPointServiceSubscriptionEffecetiveDateTime { get; set; }


    public virtual ICollection<SupplyPoint> SupplyPoints { get; set; }

    public virtual ICollection<SupplyPointService> SupplyPointServices { get; set; }


}

class SupplyPointServiceSubscriptionConfiguration : EntityTypeConfiguration<SupplyPointServiceSubscription>
{
    public SupplyPointServiceSubscriptionConfiguration()
    {   

        HasOptional(e => e.SupplyPoint).WithMany(e => e.SupplyPoints) // *
             .HasForeignKey(e => e.SupplyPointId);
        HasOptional(e => e.SupplyPointService).WithMany(e => e.SupplyPointServices) // * and here
             .HasForeignKey(e => e.SupplyPointServiceId);
    }
}

0 个答案:

没有答案
相关问题