Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiplicity not allowed. Entity Framework

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; }
}
like image 1000
MikeReynolds Avatar asked Oct 09 '13 15:10

MikeReynolds


1 Answers

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)

like image 84
Alexandre Rondeau Avatar answered Dec 08 '22 07:12

Alexandre Rondeau