One-to-One Relationships by First Key with First Entity Structure Code

I am currently getting the following error when trying to create a one-to-one relationship using Code First: System.Data.Edm.EdmAssociationEnd :: the multiplicity is not valid in the role "C001_Holding_Teste_C001_Holding_Source" in relation to "C001_Holding_Teste_C001_Holding". Since the dependent role refers to key properties, the upper limit of the multiplicity of the dependent role should be 1. My entity definitions are as follows:

[Table("C001_Holding", Schema = "Cad")]
public partial class C001_Holding
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int C001_Id { get; set; }

    [MaxLength(16)]
    public string C001_Codigo { get; set; }

    [MaxLength(100)]
    public string C001_Descricao { get; set; }
}

public class C001_Holding_Test
{
    [Key]
    public int C001_Id { get; set; }
    [MaxLength(100)]
    public string C001_TestInfo { get; set; }

    [ForeignKey("C001_Id")]
    public virtual C001_Holding C001_Holding { get; set; }
}

I did not want to use Fluent to create this relationship, does anyone know why this is happening?

Tks.

+3
source share
1 answer

ForeignKey , , ( ). , , . :

public class C001_Holding_Test
{
    [Key]
    [ForeignKey("C001_Holding")]
    public int C001_Id { get; set; }

    [MaxLength(100)]
    public string C001_TestInfo { get; set; }

    public virtual C001_Holding C001_Holding { get; set; }
}

- , . ( , , . , ...)

+5

All Articles