我收到此错误
在表“Regions”上引入 FOREIGN KEY 约束“FK_dbo.Regions_dbo.Countries_CountryId”可能会导致循环或多个级联路径。指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。无法创建约束。请参阅以前的错误。
我想知道这是否意味着我的数据库设计不好?我读到你关闭了级联或类似的东西,但我只是不确定这是否能彻底解决问题。
我只是让 EF 通过我的域类生成我的表(此时我没有使用任何数据注释或流利的映射)。
public class Country
{
public Country()
{
this.Stores = new List<Store>();
this.Regions = new List<Region>();
Id = GuidCombGenerator.GenerateComb();
}
public Guid Id { get; private set; }
private string name;
public string Name
{
get { return name; }
set
{
name = value.Trim();
}
}
private string code;
public string Code
{
get { return code; }
set
{
code = value.Trim();
}
}
public virtual ICollection<Store> Stores { get; set; }
public virtual ICollection<Region> Regions { get; set; }
}
public class City
{
public City()
{
this.Stores = new List<Store>();
Id = GuidCombGenerator.GenerateComb();
}
public Guid Id { get; private set; }
private string name;
public string Name
{
get { return name; }
set
{
name = value.Trim();
}
}
public Guid RegionId { get; set; }
public virtual Region Region { get; set; }
public virtual ICollection<Store> Stores { get; set; }
}
public class Region
{
public Region()
{
this.Cities = new List<City>();
this.Stores = new List<Store>();
Id = GuidCombGenerator.GenerateComb();
}
public Guid Id { get; private set; }
private string state;
public string State
{
get { return state; }
set
{
state = value.Trim();
}
}
public Guid CountryId { get; set; }
public virtual ICollection<City> Cities { get; set; }
public virtual Country Country { get; set; }
public virtual ICollection<Store> Stores { get; set; }
}
public class Store
{
public Store()
{
Id = GuidCombGenerator.GenerateComb();
Users = new List<User>();
}
public Guid Id { get; private set; }
public Guid CountryId { get; set; }
public Guid CityId { get; set; }
public Guid RegionId { get; set; }
public virtual City City { get; set; }
public virtual Country Country { get; set; }
public virtual Region Region { get; set; }
public virtual ICollection<User> Users { get; set; }
}
会不会是商店的原因?