Unable to determine the principal end of an association between the types

c# entity-framework

Question

I'm getting this error:

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

Here is my Customer and CustomerDetail models

[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 to CustomerDetail has a 1:1 relation.

1
14
1/25/2015 1:40:16 AM

Accepted Answer

I think that you have to specify a ForeignKey relation on the Customer property that maps to the key property exists on the entity.

[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 refers to a different error, but has a similar goal to what you are trying to achieve.

10
5/23/2017 12:14:46 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow