예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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;
 }
예제 #4
0
        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;

        }