c# - 在 EF6 Code-First 中管理 3 层表之间的级联删除
问题描述
我正在使用 EF6,我有下表。
- 产品
- 产品变体
- 产品展示
现在每个产品将有多个产品变体,每个产品变体又将有多个产品库(图像)。
以下是我设计模型的方式。
- 产品表
public class ProductsDo
{
[Key]
public int Id { get; set; }
... With all other fields pertaining to product.
public virtual List<ProductVariantsDo> ProductVariants { get; set; }
}
- 产品变体表
public class ProductVariantsDo
{
[Key]
public int Id { get; set; }
[ForeignKey("Product")]
public int ProductId { get; set; }
... with all other fields pertaining to productvariants.
public virtual ProductsDo Product { get; set; }
public virtual List<ProductGalleryDo> ProductGalleries { get; set; }
}
- ProductGallery 表。
public class ProductGalleryDo
{
[Key]
public int Id { get; set; }
[ForeignKey("ProductVariant")]
public int ProductVariantId { get; set; }
... with all other fields pertaining to productgallery
public virtual ProductVariantsDo ProductVariant { get; set; }
}
当我运行 update-database 命令时,它使用 ProductVariant 外键在 ProductGallery 上引发错误,它要求删除级联删除。但是在这里我担心如果我删除级联删除它不会在删除相应的产品变体时删除所有产品库。
谁能告诉我如何管理上述情况。
解决方案
推荐阅读
- typo3 - 备份还原后 Typo3 搞砸了
- spring-data-jpa - 子实体未在使用 onetomany 的父实体更新时插入/更新
- position - networkx:如何控制图上的节点位置
- django - django模型,如何使两个可选字段,但是当一个被填满时,另一个也必须被填满
- c++ - 为什么这段代码没有给出想要的输出?
- c++ - 为什么我的链接器脚本中的 ENTRY() 没有设置为 . =部分?
- asp.net - ASPNET Core 3.1 RedirectResult 不再适用于生产环境
- javascript - React-为什么多次调用 useEffect (即使有条件)?
- javascript - 从 googlesheets 获取日期并在 javascripts 中创建一个计数器来计算过去的天数
- jenkins - 如何确定 Jenkins Groovy 脚本的哪个参数需要 String 以及哪个 GString?