I'm using .NET framework 4.0 with Entity Framework v6 code-first.
I am creating 3 tables ("Indicadores", "Campos" and "Codigos") which use composite primary keys, but I am receiving an error when generating the model:
One or more validation errors were detected during model generation:
Codigos_Campos_Target_Codigos_Campos_Source: : The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical.
The code is here:
public class Indicadores
{
[Key, Column(Order = 0)]
public Int32 Nro_Serie { get; set; }
[MaxLength(31)]
public string Nombre { get; set; }
public List<Campos> campo { get; set; }
}
public class Codigos
{
[Key, Column(Order = 0), DataType("nvarchar"), MaxLength(31)]
public string Codigo {get;set;}
[MaxLength(31)]
public string Descripcion1 {get;set;}
[MaxLength(31)]
public string Descripcion2 {get;set;}
public Int32 CantidadPesadas {get;set;}
public Int32 PesoTotal {get;set;}
[Key, Column(Order = 1)]
public Int16 Nro_Campo { get; set; }
[ForeignKey("Nro_Campo")]
public Campos Campos { get; set; }
}
public class Campos
{
[Key, Column(Order = 0), DataType("smallint"), DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None)]
public Int16 Nro_Campo {get;set;}
[Required]
public string Nombre {get;set;}
public List<Codigos> codigo { get; set; }
[Key, Column(Order = 1)]
public Int32 Nro_Serie { get; set; }
[ForeignKey("Nro_Serie")]
public Indicadores Indicadores { get; set; }
}
Previously, I used "Campos" and "Codigos" tables with no error; The problem occurs when I include the "Indicadores" table.
Any idea of how can I solve this?