2

I'm using a 'in database' circularly linked list (cll). I'm inserting the database entries forming these 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?

JJoos
  • 587
  • 1
  • 6
  • 17

1 Answers1

2

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.

Chris Ballard
  • 3,771
  • 4
  • 28
  • 40
  • I don't have a foreign key constraint, on these fields. It is a framework error, not a database error. And I can testify my *hack* works ;). – JJoos Apr 04 '11 at 12:37
  • Ah, in which case you are probably stuck with either item 2, or your proposed solution – Chris Ballard Apr 04 '11 at 12:38
  • Your second solution would work. It would introduce some additional bookkeeping to keep track of the first item in the linked list. But it would mean i don't have erroneous data in my database. I'll accept your answer if nobody knows how to turn this error off (or has a really good explanation why it throws this error). – JJoos Apr 04 '11 at 12:45