0
votes

I'm going back to EF (Code First) and ATM trying to set up a 1-1 relationship using DataAnnotations.

public class CmsMember
{
    [Key]
    public int nodeId { get; set; }
    public string Email { get; set; }
    public string LoginName { get; set; }
    public string Password { get; set; }

    public Client Client { get; set; }
}
public class Client
{
    [ForeignKey("CmsMember")]
    public int nodeId { get; set; }
    public int ClientId { get; set; }
    public string ClientName { get; set; }

    public CmsMember CmsMember { get; set; }
}

I'm stuck on error (on add-migration command) saying:

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

Any hint would be highly appreciated.

2

2 Answers

1
votes

I think this should help you. There is the same error and your code is similar. You need to change the place of the attribute as well, should be above the property where you want to use in you case above

public CmsMember CmeMember { get; set; }
1
votes

You need key attribute because your property name doesn't match the convention.

[Key, ForeignKey("CmsMember")]
public int nodeId { get; set; }