当FK被淘汰时,GetChangeSet抛出异常 [英] GetChangeSet throws exception when FK has been nulled out

查看:120
本文介绍了当FK被淘汰时,GetChangeSet抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个非可空关系被清空,那么我调用GetChangeSet,我得到一个这样的错误:

If a non-nullable relationship is nulled out, then I call GetChangeSet, I get an error like this:

尝试删除X和Y之间的关系。但是,其中一个关系的外键(XA)不能设置为null

An attempt was made to remove a relationship between a X and a Y. However, one of the relationship's foreign keys (X.A) cannot be set to null

这真是令人讨厌。是的,我可以看到为什么在SubmitChanges上必须发生这种错误,但我不是要提交任何更改。我只是想找出用户编辑过的对象(所以我可以对它们进行一些验证,因为它发生了)。我认为系统可以告诉我哪些对象已被编辑,无论它们是否满足强制关系。

This is a real nuisance. Yes, I can see why this kind of error must happen on SubmitChanges, but I'm not trying to submit any changes.  I'm just trying to find out which objects the user has edited (so I can run some validation on them, as it happens).  I would think that the system could tell me which objects have been edited regardless of whether or not they satisfy mandatory relationships.

有没有办法在不触发此错误的情况下获得更改集?

Is there any way that I can get a change set without triggering this error?

如果失败,则是有任何支持的方式来获取所有对象的列表"在...中" DataContext? (如果我无法获得更改集,我可以在我查看所有对象时进行解决方法。)

Failing that, is there any supported way to get a list of all the objects "in" the DataContext?  (If I can't get a change set, I could do a workaround where I look at all the objects).

John

推荐答案

具有讽刺意味的是,我正在获取更改的对象,以便我可以检查它们的强制性字段已设置。不幸的是,当缺少必需的外键式关系时,我甚至无法获得已更改对象的列表。

The ironic thing is that I'm getting the changed objects so that I can check their mandatory fields are set.  Unfortunately, when mandatory foreign-key-style relationships are missing, I can't even get the list of changed objects.

任何人?


这篇关于当FK被淘汰时,GetChangeSet抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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