I currently have the following code to detect a duplicate entry, I suppose there is a cleaner way, but I have yet to find it.... can anyone guide me if this is the correct way?
catch (DbUpdateException e)
{
if (e.InnerException != null)
if (e.InnerException is UpdateException)
if (e.InnerException.InnerException != null)
if (e.InnerException.InnerException is SqlException)
{
SqlException ex = e.InnerException.InnerException as SqlException;
if (ex.Number == 2601)
{
ModelState.AddModelError("", "Unit number already exists");
}
}
}
}
}