首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在实体框架中级联删除?

如何在实体框架中级联删除?
EN

Stack Overflow用户
提问于 2012-11-22 18:45:13
回答 2查看 5.3K关注 0票数 4

我的模型中有两个对象

Car和carPart

具有1:n关系。

我想删除级联实体车。当我删除时,我得到了以下异常:

代码语言:javascript
复制
 The operation failed: The relationship could not be changed because one or 
 more of the foreign-key properties is non-nullable. When a change is made 
 to a relationship, the related foreign-key property is set to a null value. 
 If the foreign-key does not support null values, a new relationship must 
 be defined, the foreign-key property must be assigned another non-null value, 
 or the unrelated object must be deleted.

我认为它会先删除汽车对象,然后再删除汽车部件。

由于外键的原因,这是不可能的。

我该怎么处理呢?

我想,很明显,首先删除carPart,然后只删除汽车。

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-22 18:52:04

票数 6
EN

Stack Overflow用户

发布于 2012-11-22 18:47:27

如果您想要级联删除,则在数据库级别设置级联删除。您收到错误,因为SQL不允许删除。

您不必在Entity Framework中执行此操作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13511005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档