【发布时间】:2014-11-28 02:20:40
【问题描述】:
实体类型 'Profile' 和 'Country' 不能共享表 'Countries',因为它们不在同一类型层次结构中,或者与匹配的主对象没有有效的一对一外键关系它们之间的键。
【问题讨论】:
标签: asp.net
实体类型 'Profile' 和 'Country' 不能共享表 'Countries',因为它们不在同一类型层次结构中,或者与匹配的主对象没有有效的一对一外键关系它们之间的键。
【问题讨论】:
标签: asp.net
尝试删除
public int? CountryID { get; set; }
来自 UserProfile 所以它看起来像这样:
public class UserProfile
{
[Key]
public int UserID { get; set; }
public virtual Country Country { get; set; }
}
public class Country
{
public Country()
{
Profiles = new HashSet<UserProfile>();
}
[Key]
public int CountryID { get; set; }
public ICollection<UserProfile> Profiles { get; set; }
}
另一件事:你有 ICollection<Profile> 而不是 ICollection<UserProfile>
【讨论】: