Linq2SQL dedicated to insert / delete on a table with unique constraints

I have a table that looks like this:

TABLE Foo
{
  Guid Id [PK],
  int A [FK],
  int B [FK],
  int C [FK],
}

And a unique restriction over A, B and C.

Now let's say, for example, you insert a row with a fresh PK with A = 1, B = 1, C = 1.

SubmitChanges(), everyone is happy.

Now you are editing the table.

You delete the previous entry and insert the row with PK Fresk with A = 1, B = 1, C = 1.

SubmitChanges()BOOM! Exception of an exclusive key SQL constraint.

From what I see, he tries to insert a new record first, and then try to delete the previous one. I can even understand that it is impossible to determine the order that should happen.

But what can I do about it? Would make these 3 fields a composite PK (and deleting the old one) better, or even not working?

"" - ( ).

+5
2

- ( TransactionScope) - SubmitChanges, SubmitChanges, , , ( -back, ).

, IIRC. TransactionScope , , .

, SP, , SP .

+3

. - "" "", . "". .

, , InsertOnSubmit/DeleteOnSubmit, 2 , , , .

+1

All Articles