2013-05-30 8 views
14

Dostaję taki błąd:Nie można określić główne koniec związku między typami

Unable to determine the principal end of an association between the types CustomerDetail and Customer.

Oto moje Customer i CustomerDetail modele

[Table("CUSTOMER")] 
public class Customer 
{ 
    [Required] 
    [Column("CUSTOMER_ID")] 
    public int Id {get; set;} 

    [Column("FIRST_NAME")] 
    public string FirstName {get; set;} 
    // other fields 

    public virtual CustomerDetail customerDetail {get; set;} 
} 

[Table("CUSTOMER_DETAIL")] 
public class CustomerDetail 
{ 
    [Required] 
    [Column("CUSTOMER_DETAIL_ID")] 
    public int Id {get; set;} 
    // other fields 

    public virtual Customer Customer {get; set;} 
} 

Customer do CustomerDetail ma 1: 1 relacja.

Odpowiedz

10

Myślę, że musisz podać relację ForeignKey na właściwości Customer, która odwzorowuje właściwości klucza w obiekcie.

[Table("CUSTOMER_DETAIL")] 
public class CustomerDetail 
{ 
    [Required] 
    [Column("CUSTOMER_DETAIL_ID")] 
    public int Id {get; set;} 
    // other fields 

    [ForeignKey("Id")] 
    public virtual Customer Customer {get; set;} 
} 

This question odnosi się do innego błędu, ale ma podobny cel, do czego staramy się osiągnąć.

Powiązane problemy