'ORA-00001: unique constraint - recognize faulty record
Let's say we have Oracle database with table called X. X** has deferred unique constraint on two of its columns. We have piece of code adding records to X.
This operation is wrapped into System.Transactions.TransactionScope. We are using EF "database first" DbModel with Devart.Data.Oracle driver (version 9.14.1382.0).
From time to time we are attempting to add record that violates unique constraint so exception is thrown when committing transaction:
ORA-00001: unique constraint (X_MD.AK_MD_DELAY_REASON) violated.
I am wondering if there's a way to recognize which record exactly caused this error. So far I am aware of two options:
- overriding ValidateEntity method of DbModel and checking columns of new records whether they fulfil unique constraint in code. Checking this each time we add records would decrease performance
- DbUpdateException contains Entries collection with records that have caused given error. However (maybe due to usage of TransactionsScope) this type of exception is not present at any level of exception hierarchy thrown in our case (neither main exception or inner exception)
But maybe there are other ways to find faulty records in such cases?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
