Entityframework 6级联删除 [英] Entityframework 6 cascading delete

查看:280
本文介绍了Entityframework 6级联删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,



i在entityframework 6中有级联删除的大问题。

i有一个简单的数据库只有2个表,人和地址,

每个人可以有0个或多个地址 - > 1:n关系。

当我删除一个人时,所有地址也被删除 - >太棒了!

但是当我试图删除一个人的所有地址时,我得到一个例外:

操作失败:因为一个或多个关系无法改变外键属性是不可为空的。当对关系进行更改时,相关的外键属性将设置为空值。如果外键不支持空值,则必须定义新关系,必须为外键属性分配另一个非空值,或者必须删除不相关的对象。



过去2天我在互联网上搜索过,我发现唯一可行的方法是创建一个组合的主键,但这对我来说也不起作用。





谢谢

Manuel

Hi experts,

i have big problems with cascading deletes in entityframework 6.
i have a simple database with just 2 tables, persons and addresses,
each Person can have 0 or many addresses -> 1:n relationship.
When i delete a person all addresses are also deleted -> GREAT!
But when i try to delete all addresses of a person i get an exception:
"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."

I have searched the Internet the last 2 days and the only thing i found that should work was to create a combined Primary key, but this also does not work for me.


Thanks
Manuel

推荐答案

请阅读我的评论问题。



看看这里:解决方案:操作失败:由于一个或多个外键属性不可为空,因此无法更改关系 [ ^ ]
Please, read my comment to the question.

Have a look here: Solution to: "The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable"[^]


这篇关于Entityframework 6级联删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆