All relationships in your model are required because all foreign key properties (CountryId
, RegionId
, CityId
) are not nullable. For required one-to-many relationships EF will enable cascading delete by convention.
Country
and Region
have multiple delete paths to the Store
table, for example if you delete a Country
the related Store
s can be deleted via three different cascading paths (which is not allowed with SQL Server):
Country
-> Store
Country
-> Region
-> Store
Country
-> Region
-> City
-> Store
You must avoid such ambiguous delete paths by either disabling cascading delete using Fluent API or by defining some of the relationships as optional (with a nullable foreign key Guid?
).
Or remove the Stores
collections (and the inverse references and FK properties) from all entities except City
. To me those collections look redundant because you can find all stores in a Country
by navigating through the Regions.Cities.Stores
collections.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…