public static DataOperationException ToDataOperationException(this System.Data.Entity.Infrastructure.DbUpdateException dbUpdateException) { DataOperationException result = null; Exception innerMostException = dbUpdateException.InnerMostException(); var sqlException = innerMostException as SqlException; //if (innerMostException is SqlException) if (innerMostException.GetType().IsAssignableFrom(typeof(SqlException))) if (sqlException != null) { result = sqlException.ToDataOperationException(); } else { result = new DataOperationException("Unknown Data Error", dbUpdateException); } return(result); }
public static DataOperationException ToDataOperationException(this SqlException ex) { DataOperationException dataException = null; if (ex.Errors.Count > 0) // Assume the interesting stuff is in the first error { switch (ex.Errors[0].Number) { case 547: // Foreign Key violation dataException = new DataOperationException("Foreign Key violation.", ex); break; case 2601: // Primary key violation dataException = new DataOperationException("Primary key violation.", ex); break; default: dataException = new DataOperationException("Unknown data exception.", ex); break; } } return(dataException); }
public static DataOperationException ToDataOperationException(this SqlException ex) { DataOperationException dataException = null; if (ex.Errors.Count > 0) // Assume the interesting stuff is in the first error { switch (ex.Errors[0].Number) { case 547: // Foreign Key violation dataException = new DataOperationException("Foreign Key violation.", ex); break; case 2601: // Primary key violation dataException = new DataOperationException("Primary key violation.", ex); break; default: dataException = new DataOperationException("Unknown data exception.", ex); break; } } return dataException; }
public static DataOperationException ToDataOperationException(this System.Data.Entity.Infrastructure.DbUpdateException dbUpdateException) { DataOperationException result = null; Exception innerMostException = dbUpdateException.InnerMostException(); var sqlException = innerMostException as SqlException; //if (innerMostException is SqlException) if (innerMostException.GetType().IsAssignableFrom(typeof(SqlException))) if (sqlException != null) { result = sqlException.ToDataOperationException(); } else { result = new DataOperationException("Unknown Data Error", dbUpdateException); } return result; }