Mapping foreign key to non primary surrogate key column in EF code first
<pre><code>public class A    
{   
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public virtual int Aid { get; set; }    

    public virtual ICollection&lt;B&gt; B { get; set; }    
}


public class B
{    
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]     
    public virtual int Bid { get; set; }

    [Key]
    [Column(Order = 0)]
    [Required]           
    Public virtual string BName {get ; set}

    [Key]
    [Column(Order = 1)]
    [Required]      
    public virtual int Aid { get; set; }

    [ForeignKey("Aid")]
    public virtual  A A { get; set; }

    public virtual ICollection&lt;C&gt; C { get; set; }    
}


public class C
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]     
    public virtual int Cid { get; set; }

    [Key]
    [Column(Order = 0)]
    [Required]    
    Public virtual string CName {get ; set}    

    [Key]
    [Column(Order = 1)]
    [Required]          
    public virtual int Bid { get; set; }

     [ForeignKey("Bid")]
     public virtual  B B { get; set; } 
}
</code></pre>

<p>relationship  between B and C is troubling me  .I dont want to include BName as foreign key in Class C </p>

<blockquote>
  <p>Error : The number of properties in the Dependent and Principal Roles
  in a relationship constraint must be identical</p>
</blockquote>

<p>I understand the error but I want to point to C class only by Bid ,how I can achieve it without disturbing the relationship between A and B.</p>