问题描述
我有两个数据源(比如Line和Billing)。实体Line.A和Billing.B之间的关系为0..1比1。 Line.A与Line.C也有1:N关系。每当我删除B时,我都需要级联删除,A被删除以及(与
所有Cs一起)。
I have two data sources (let's say Line and Billing). Entities Line.A and Billing.B have an 0..1 to 1 relationship. Line.A has also a 1:N relationship with Line.C. I need a cascading delete whenever I delete B, A is deleted as well (together with all Cs).
我尝试了以下的一些变体,但我仍然得到一个ValidationError,说我无法删除Line.A或Line.C因为有引用它的对象。
I tried some variants of the following, but I still get a ValidationError saying that I cannot delete Line.A or Line.C because there are objects referencing it.
partial void Bs_Deleting(B entity)
{
var a= entity.A;
var cs= a.Cs.ToArray();
for (int i = cs.Length - 1; i >= 0; i--)
cs[i].Delete();
a.Delete();
DataWorkspace.LineData.SaveChanges();
}
如果我没有这种部分方法,删除工作正常,Billing中的层次结构被正确删除,但什么都没有在行中删除。您对我如何实现此类功能有任何想法吗?提前致谢!
Deletion works if I don't have this partial method, with hierarchies in Billing being correctly deleted, but nothing is deleted in Line. Do you have any idea on how I could implement this type of functionality? Thanks in advance!
推荐答案
这被称为_After_ B已从商店中删除。
That gets called _After_ the B has been deleted from the store.
这篇关于级联删除不同的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!