"A cycle was detected in the set of changes" When trying to add a circularly linked list to the database
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:
- Remove the foreign key constraint.
- 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.
精彩评论