Asp.net 无法共享没有匹配主键的表
实体类型“Profile”和“Country”不能共享表“Countries”,因为它们不在同一类型层次结构中,或者它们之间没有有效的一对一外键关系以及匹配的主键。Asp.net 无法共享没有匹配主键的表,asp.net,Asp.net,实体类型“Profile”和“Country”不能共享表“Countries”,因为它们不在同一类型层次结构中,或者它们之间没有有效的一对一外键关系以及匹配的主键。请尝试删除 public int? CountryID { get; set; } 从UserProfile中,看起来如下所示: public class UserProfile { [Key] public int UserID { get; set; } public virtual Country C
请尝试删除
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; }
}
公共类用户配置文件
{
[关键]
public int UserID{get;set;}
公共虚拟国家{get;set;}
}
公营国家
{
公共国家()
{
Profiles=newhashset();
}
[关键]
public int CountryID{get;set;}
公共ICollection配置文件{get;set;}
}
另一件事:你有ICollection
而不是ICollection