我遇到了这个错误:
引入“FK_dbo.Regions_dbo.Countries_CountryId”表的FOREIGN KEY限制可能导致循环或多个级联路径。请指定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; }
}
是因为商店吗?
Store
类....而且我也没有看到任何定义级联删除的代码... - marc_s