我有一个User
<Country
模型。用户属于一个国家,但可能不属于任何国家(外键为空)。
我该怎么设置?当我尝试插入一个空国家的用户时,它告诉我它不能为空。
模型如下:
public class User{
public int CountryId { get; set; }
public Country Country { get; set; }
}
public class Country{
public List<User> Users {get; set;}
public int CountryId {get; set;}
}
错误: 因为相应的主键值不存在,无法插入外键值。[外键约束名称=Country_Users]