c# - Linq2SQL dealing with inserts/deletes on table with unique constraints -


I have a table that looks like the following:

  table fu {GUID} ID [PK], Int a [FK], Int B [FK], Int C [FK],}  

and unique obligation on A, B and C

Now, for example, say you enter a line with a fresh PK with A = 1, B = 1, C = 1.

submit () , all happy.

Now you can edit the table.

You remove the previous entry, and enter a line with a Frescak PK with A = 1, B = 1, C = 1.

P> Submit Changelog () Boom! Unique Key Barrier Sql Exception

What I can see, first tries to put a new record, and then tries to remove the last one. I can also understand that it is not possible to determine the need to be.

But what can I do about it? Making those 3 areas aggregate (and old removal) can be a better solution or will it not work?

For now, 'Solution' is to remove unique obstacles from DB (but I will not do this).

An option will be to create a transaction (either connection-out transaction, or a TransactionScope ) - Delete the record and add submit changelog , record and submit , then finally the transaction (or roll -back if you are blowing) .

Note that you can associate a connection-bound transaction through the Data-Container Constructor IIRC. TransactionScope should also work, and it's easy to do - but not quite efficient.

Alternatively, write a SP that does this swap job in the database, and via SP data-reference.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -