开发者

"A cycle was detected in the set of changes" When trying to add a circularly linked list to the database

开发者 https://www.devze.com 2023-02-22 11:11 出处:网络
I\'m using a \'in database\' circularly linked list (cll). I\'m inserting the database entries forming th开发者_JAVA技巧ese cll\'s using Linq to Sql.

I'm using a 'in database' circularly linked list (cll). I'm inserting the database entries forming th开发者_JAVA技巧ese cll's using Linq to Sql.

They have the general form:

id uuid | nextId uuid | current bit

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".

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?


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.

I suspect your choices are:

  1. Remove the foreign key constraint.
  2. Store in the DB as a linked list, and only join the head with the tail in your code.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消