14

我收到此错误:

无法确定类型 CustomerDetail 和 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;} 
}

CustomertoCustomerDetail具有 1:1 的关系。

4

1 回答 1

9

我认为您必须在实体上指定映射到 key 属性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;} 
}

这个问题指的是一个不同的错误,但与你想要实现的目标相似。

于 2013-05-30T18:06:13.297 回答