2013-05-30 21 views
14

sto ottenendo questo errore:Impossibile determinare il fine principale di un'associazione tra i tipi

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

ecco la mia Customer e CustomerDetail modelli

[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 a CustomerDetail ha un 1: 1 relazione

risposta

10

Penso che sia necessario specificare una relazione ForeignKey sulla proprietà Customer che esegue il mapping alla proprietà chiave esistente nell'entità.

[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 si riferisce ad un errore diverso, ma ha un obiettivo simile a quello che si sta cercando di ottenere.

Problemi correlati