2013-05-30 22 views
14

我得到這個錯誤:無法確定類型之間的關聯的主要結束

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

這是我CustomerCustomerDetail模型

[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;} 
} 

CustomerCustomerDetail有一個1: 1關係。

回答

10

我認爲你必須指定一個ForeignKey關係Customer屬性映射到實體上存在的關鍵屬性。

[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是指不同的錯誤,但也有類似的目標,你想達到的目標。

相關問題