Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 无法共享没有匹配主键的表_Asp.net - Fatal编程技术网

Asp.net 无法共享没有匹配主键的表

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

实体类型“Profile”和“Country”不能共享表“Countries”,因为它们不在同一类型层次结构中,或者它们之间没有有效的一对一外键关系以及匹配的主键。

请尝试删除

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