I have an application that allows multiple users and a database table to have 2 identifiers as a composite key. These identifiers are also foreign keys from another table. Therefore, when 2 users try to add an entry to this column with the same identifiers, one of them gets an UpdateException due to a violation of the main key constant. I already found out that it should be processed as follows:
try
{
result = base.SaveChanges(options);
}
catch (UpdateException ex)
{
SqlException innerException = ex.InnerException as SqlException;
if (innerException != null && innerException.Number == 2627 || innerException.Number == 2601)
{
}
else
{
throw;
}
}
"//Handle here". , "" .
, : , , , .
?