Multiplicity not allowed. Entity Framework

2020-04-04 03:49发布

I am attempting to use MVC4 for the first time and am receiving the following error when I try to create a controller? Could someone kindly steer me in the right direction?


Microsoft Visual Studio

System.Data.Entity.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'PropertyData_DNISData_Target' in relationship 'PropertyData_DNISData'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.

public class PropertyData
{
    [Key]
    public virtual string PropertyID { get; set; }

    [ForeignKey ("DNISData")]
    public virtual string DNIS { get; set; }

    public virtual string PropertyName { get; set; }
    public virtual string PropertyGreeting { get; set; }
    public virtual string PropertyOperator { get; set; }
    public virtual string InvalidEntryPrompt { get; set; }
    public virtual string NoEntryPrompt { get; set; }
    public virtual string Comment { get; set; }
    public virtual DNISData DNISData { get; set; }

}

public class DNISData
{
    [Key]
    public virtual string DNIS { get; set; }
    [ForeignKey("PropertyData")]
    public string PropertyID { get; set; }
    public virtual string VDN { get; set; }
    public virtual string PropertyGreeting { get; set; }
    public virtual string Comment { get; set; }
    public virtual PropertyData PropertyData { get; set; }
}

public class DigitData
{
    [ForeignKey ("DNISData")]
    [Key]
    public virtual string DNIS { get; set; }
    [Key]
    public virtual string Digit { get; set; }
    public virtual string InvalidEntryPrompt { get; set; }
    public virtual DNISData DNISData { get; set; }
}

1条回答
孤傲高冷的网名
2楼-- · 2020-04-04 04:33

You have a 1 to 1 relationship between PropertyData and DNISData. This can only be done via shared primarykey in EntityFramework.

This question can give you the anwser you are looking for:

How to declare one to one relationship using Entity Framework 4 Code First (POCO)

查看更多
登录 后发表回答