0

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.

Chris Hermut
  • 1,708
  • 3
  • 17
  • 32

2 Answers2

1

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; }
Community
  • 1
  • 1
1

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

[Key, ForeignKey("CmsMember")]
public int nodeId { get; set; }
Yuliam Chandra
  • 14,494
  • 12
  • 52
  • 67
  • Thanks it solved the EF issues but now when trying to insert data to DB I get "Cannot insert explicit value for identity column in table 'Client' when IDENTITY_INSERT is set to OFF". Any idea? – Chris Hermut Aug 27 '14 at 09:54
  • the default convention for numeric key is identity, if you have sql query syntax that explicitly sets the id, that probably would be the cause – Yuliam Chandra Aug 27 '14 at 09:56