how to tell the user that a record has not been deleted because it has other entities that inherit its primary key by means of try / catch?
try
{
db.usuarios.Remove(usuario);
}
catch(?????)
{
???????
}
how to tell the user that a record has not been deleted because it has other entities that inherit its primary key by means of try / catch?
try
{
db.usuarios.Remove(usuario);
}
catch(?????)
{
???????
}
If you are not enabled, the cascade deletion should control the exception using something like
try
{
db.usuarios.Remove(usuario);
}
catch (DbUpdateException ex)
{
var sqlException = ex.GetBaseException() as SqlException;
if (sqlException != null)
{
}
}
Can not catch SqlException in Entity Framework
by getting the exception of sql you could go through the errors and validate the Number
to determine if there are any related to Foreign Key violation