title: Problems with Primary Keys and Foreign Keys
body: <p>I am trying to create one-to-one relation between 2 classes with a composite key. I've done it before in classes with simple PK and it works but now i need to join a class with composite PK and is not working.</p>
  
  <p>Here is the code, I am trying to join SFI_EstadisticaVentasFcst with SFI_Clientes</p>
  
  <pre><code>public class SFI_Clientes
  {
      [DatabaseGenerated(DatabaseGeneratedOption.None)]
      [Key]
      [Column(Order = 0)]
      public string ID_Empresa { get; set; }
      [Key]
      [Column(Order = 1)]
      public string ID_Cliente { get; set; }
      [Key]
      [Column(Order = 2)]
      [DataType(DataType.Date)]
      [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
      public DateTime Fecha_Desde { get; set; }
      [Key]
      [Column(Order = 3)]
      [DataType(DataType.Date)]       
      [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
      public DateTime Fecha_Hasta { get; set; }
      [DisplayName("NOMBRE")]
      public string nombre { get; set; }
      [DisplayName("ID VENDEDOR")]
      public string ID_Vendedor { get; set; }
      [DisplayName("ID NAM")]
      public string ID_NAM { get; set; }
      [DisplayName("ID KAM")]
      public string ID_KAM { get; set; }
  
      public virtual SFI_Vendedor vendedor { get; set; }
      public virtual SFI_Kam kam { get; set; }
      public virtual SFI_Nam nam { get; set; }
  
  }
  
  public class SFI_EstadisticaVentasFcst
  {
      [DatabaseGenerated(DatabaseGeneratedOption.None)]
      [Key]
      [Column(Order = 0)]
      [DisplayFormat(DataFormatString = "{0:0}")]
      public decimal anio { get; set; }
      [Key]
      [Column(Order = 1)]
      [DisplayFormat(DataFormatString = "{0:0}")]
      public decimal periodo { get; set; }
      [ForeignKey("cliente"), Column(Order = 0)]
      public string ID_Empresa { get; set; }
      [Key]        
      [ForeignKey("cliente"), Column(Order = 1)]
      public string ID_Cliente { get; set; }
      [Key]
      [Column(Order = 3)]
      public string producto { get; set; }
      public decimal fcst_cajas { get; set; }
      public decimal fcst_niv { get; set; }
      public decimal fcst_gsu { get; set; }
      public decimal venta_cajas { get; set; }
      public decimal venta_niv { get; set; }
      public decimal venta_gsu { get; set; }
      public decimal avance_cajas { get; set; }
      public decimal avance_gsu {get; set; }
  
      public virtual SFI_Clientes cliente { get; set; }
      public virtual SFI_JerarquiaProductos jerarquiaProductos { get; set; }
  </code></pre>
  
  <p>Here is the problemn:</p>
  
  <pre><code>public JsonResult cargarListaEmpresas(string idEmpresa, string cliente, string vendedor, string nam, string kam, string categoriaProductos, DateTime fechaDesde, DateTime fechaHasta )
      {
          var c = db.SFI_EstadisticaVentasFcstDbSet.Where
              (x =&gt;
              (string.IsNullOrEmpty(idEmpresa) ? true : x.ID_Empresa== idEmpresa) &amp;&amp;
              (string.IsNullOrEmpty(cliente) ? true : x.ID_Cliente == cliente) &amp;&amp;
              (string.IsNullOrEmpty(vendedor) ? true : x.cliente.ID_Vendedor == vendedor) &amp;&amp;
              (string.IsNullOrEmpty(kam) ? true : x.cliente.ID_KAM == kam) &amp;&amp;
              (string.IsNullOrEmpty(nam) ? true : x.cliente.ID_NAM == nam) &amp;&amp;
              (string.IsNullOrEmpty(categoriaProductos) ? true : x.jerarquiaProductos.descripcion_1 == categoriaProductos) &amp;&amp;
              (x.cliente.Fecha_Desde == fechaDesde) &amp;&amp;
              (x.cliente.Fecha_Hasta == fechaHasta)
              ).Distinct().OrderBy(s =&gt; s.ID_Empresa).Select(x =&gt; new SelectListItem
              {
                  Text = x.ID_Empresa.ToString(),
                  Value = x.ID_Empresa
              }).Distinct().OrderBy(x =&gt; x.Text).ToList();
  
          ViewBag.empresas = c;
          return Json(c, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p>The error is:
  "One or more validation errors were detected during model generation:
  SFI_EstadisticaVentasFcst_cliente_Target_SFI_EstadisticaVentasFcst_cliente_Source: : The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical."</p>