Dear all,
What is the recommended way to handle database constraints and display friendly user messages?
I am
to show it, but here is how I handle fk constraints:
/// <summary>
/// Removes the quota.
/// </summary>
/// <param name="quotaId">The quota id.</param>
/// <returns>True if the quota was deleted.</returns>
internal bool RemoveQuota(long quotaId) {
using (DataAccessAdapter adapter = new DataAccessAdapter()) {
try {
QuotaEntity quota = new QuotaEntity(quotaId);
return adapter.DeleteEntity(quota);
} catch (ORMException ex) {
if (ex.Message.Contains("FK_ProjectQuota_Quota") || ex.Message.Contains("FK_ProjectHistoricalQuota_Quota")) {
throw new Application.UserMessageException("Unable to delete this quota because it is in use by at least one project.");
}
throw new Application.UserMessageException(ex.Message);
}
}
}
Should I first do a query to check that the entity is not in use or is there another exception strategy I can use?
With kind regards,
Tore.