"在设定变更]中检测到循环;当试图圆链表添加到数据库 [英] "A cycle was detected in the set of changes" When trying to add a circularly linked list to the database

查看:149
本文介绍了"在设定变更]中检测到循环;当试图圆链表添加到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是数据库循环链表(CLL)。我插入形成使用LINQ to SQL执行这些CLL的数据库条目。

I'm using a 'in database' circularly linked list (cll). I'm inserting the database entries forming these cll's using Linq to Sql.

他们的一般形式:

id uuid | nextId uuid | current bit

如果我尝试做一个的SubmitChanges与几个对象形成了完整的CLL,我得到的错误的组更改检测到循环。

If i try to do a SubmitChanges with a few objects forming a complete cll, i get the error "A cycle was detected in the set of changes".

我可以通过在一个单独的SubmitChanges链表通知绕过这个,但这样做有两个倒边:我失去了我的能力在一个做到这一点交易。对于一个小的时间在我的数据库中的数据是不正确的。

I can circumvent this by making the linked list 'circular' in a separate SubmitChanges, but this has two down sides: I'm losing my capability to do this in one transaction. For a small period the data in my database isn't correct.

有没有办法来解决这个问题?

Is there a way to fix this behaviour?

推荐答案

数据库需要强制执行的约束上,和我想象你有 nextId 和C>标识。如果这条产业链关系,导致回到起点(如你发现)数据库不会允许它

The database needs to enforce its contraints, and I imagine you have a foreign key constraint between nextId and Id. If this chain of relations leads back to the start (as you have found) the database will not allow it.

我怀疑你的选择是:


  1. 删除外键约束。

  2. 存储在数据库中的一个链接列表,并只能加入同尾头在你的代码。

即使你的第二个选项将不起作用,因为DB不会允许你添加这最后引用。

Even your second option won't work, as the DB won't allow you to add this last reference.

这篇关于"在设定变更]中检测到循环;当试图圆链表添加到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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