| | | 1 | | // ReSharper disable once CheckNamespace |
| | | 2 | | namespace Microsoft.EntityFrameworkCore; |
| | | 3 | | |
| | | 4 | | /// <summary>Errors for a failed <c>SaveChanges</c> (<see cref="DbUpdateException"/>), by SQL Server error number. Type: |
| | | 5 | | public static class DbUpdateExceptions |
| | | 6 | | { |
| | | 7 | | private const string DatabaseError = nameof( DatabaseError ); |
| | | 8 | | |
| | | 9 | | |
| | | 10 | | /// <summary>A row with the same unique value already exists (SQL 2627, 2601).</summary> |
| | | 11 | | /// <param name="exception">The exception, kept for logs.</param> |
| | | 12 | | /// <param name="additionalData">Extra values for logs.</param> |
| | | 13 | | /// <returns>The <c>UniqueConstraintViolation</c> error (severity High).</returns> |
| | | 14 | | public static Error UniqueConstraintViolation( DbUpdateException exception, IReadOnlyDictionary<string, object>? add |
| | 7 | 15 | | => new( nameof( UniqueConstraintViolation ), DatabaseError, "سجل بهذه القيمة موجود بالفعل.", "A record with this |
| | 7 | 16 | | Severity.High, exception, additionalData ); |
| | | 17 | | |
| | | 18 | | /// <summary>A foreign key or check constraint blocks the change (SQL 547).</summary> |
| | | 19 | | /// <param name="exception">The exception, kept for logs.</param> |
| | | 20 | | /// <param name="additionalData">Extra values for logs.</param> |
| | | 21 | | /// <returns>The <c>ConstraintViolation</c> error (severity High).</returns> |
| | | 22 | | public static Error ConstraintViolation( DbUpdateException exception, IReadOnlyDictionary<string, object>? additiona |
| | 0 | 23 | | => new( nameof( ConstraintViolation ), DatabaseError, "لا يمكن إجراء هذه العملية بسبب انتهاك قيد.", |
| | 0 | 24 | | "Cannot perform this operation due to a constraint violation.", Severity.High, exception, additionalData |
| | | 25 | | |
| | | 26 | | /// <summary>A required column got <c>NULL</c> (SQL 515).</summary> |
| | | 27 | | /// <param name="exception">The exception, kept for logs.</param> |
| | | 28 | | /// <param name="additionalData">Extra values for logs.</param> |
| | | 29 | | /// <returns>The <c>RequiredFieldMissing</c> error (severity Medium).</returns> |
| | | 30 | | public static Error RequiredFieldMissing( DbUpdateException exception, IReadOnlyDictionary<string, object>? addition |
| | 0 | 31 | | => new( nameof( RequiredFieldMissing ), DatabaseError, "حقل مطلوب مفقود.", "A required field is missing.", Sever |
| | 0 | 32 | | additionalData ); |
| | | 33 | | |
| | | 34 | | /// <summary>A value is longer than its column (SQL 8152).</summary> |
| | | 35 | | /// <param name="exception">The exception, kept for logs.</param> |
| | | 36 | | /// <param name="additionalData">Extra values for logs.</param> |
| | | 37 | | /// <returns>The <c>DataTooLong</c> error (severity Medium).</returns> |
| | | 38 | | public static Error DataTooLong( DbUpdateException exception, IReadOnlyDictionary<string, object>? additionalData = |
| | 0 | 39 | | => new( nameof( DataTooLong ), DatabaseError, "القيمة المقدمة طويلة جدًا للحقل.", "The provided value is too lon |
| | 0 | 40 | | Severity.Medium, exception, additionalData ); |
| | | 41 | | |
| | | 42 | | /// <summary>A number is out of range for its column (SQL 8115).</summary> |
| | | 43 | | /// <param name="exception">The exception, kept for logs.</param> |
| | | 44 | | /// <param name="additionalData">Extra values for logs.</param> |
| | | 45 | | /// <returns>The <c>NumericOverflow</c> error (severity Medium).</returns> |
| | | 46 | | public static Error NumericOverflow( DbUpdateException exception, IReadOnlyDictionary<string, object>? additionalDat |
| | 0 | 47 | | => new( nameof( NumericOverflow ), DatabaseError, "القيمة الرقمية خارج النطاق.", "The numeric value is out of ra |
| | 0 | 48 | | exception, additionalData ); |
| | | 49 | | |
| | | 50 | | /// <summary>A value can't be converted to the column type (SQL 245, 241, 242).</summary> |
| | | 51 | | /// <param name="exception">The exception, kept for logs.</param> |
| | | 52 | | /// <param name="additionalData">Extra values for logs.</param> |
| | | 53 | | /// <returns>The <c>InvalidDataType</c> error (severity Medium).</returns> |
| | | 54 | | public static Error InvalidDataType( DbUpdateException exception, IReadOnlyDictionary<string, object>? additionalDat |
| | 0 | 55 | | => new( nameof( InvalidDataType ), DatabaseError, "نوع بيانات غير صالح للحقل.", "Invalid data type for the field |
| | 0 | 56 | | exception, additionalData ); |
| | | 57 | | |
| | | 58 | | /// <summary>The transaction was chosen as a deadlock victim (SQL 1205). Safe to retry.</summary> |
| | | 59 | | /// <param name="exception">The exception, kept for logs.</param> |
| | | 60 | | /// <param name="additionalData">Extra values for logs.</param> |
| | | 61 | | /// <returns>The <c>Deadlock</c> error (severity High).</returns> |
| | | 62 | | public static Error Deadlock( DbUpdateException exception, IReadOnlyDictionary<string, object>? additionalData = nul |
| | 0 | 63 | | => new( nameof( Deadlock ), DatabaseError, "حدث تعثر. يرجى المحاولة مرة أخرى.", "A deadlock occurred. Please try |
| | 0 | 64 | | exception, additionalData ); |
| | | 65 | | |
| | | 66 | | /// <summary>The command timed out (SQL -2). Safe to retry.</summary> |
| | | 67 | | /// <param name="exception">The exception, kept for logs.</param> |
| | | 68 | | /// <param name="additionalData">Extra values for logs.</param> |
| | | 69 | | /// <returns>The <c>Timeout</c> error (severity High).</returns> |
| | | 70 | | public static Error Timeout( DbUpdateException exception, IReadOnlyDictionary<string, object>? additionalData = null |
| | 0 | 71 | | => new( nameof( Timeout ), DatabaseError, "انتهت مهلة العملية. يرجى المحاولة مرة أخرى.", "The operation timed ou |
| | 0 | 72 | | Severity.High, exception, additionalData ); |
| | | 73 | | |
| | | 74 | | /// <summary>Any other save failure.</summary> |
| | | 75 | | /// <param name="exception">The exception, kept for logs.</param> |
| | | 76 | | /// <param name="additionalData">Extra values for logs.</param> |
| | | 77 | | /// <returns>The <c>UnexpectedError</c> error (severity Unknown).</returns> |
| | | 78 | | public static Error UnexpectedError( DbUpdateException exception, IReadOnlyDictionary<string, object>? additionalDat |
| | 32 | 79 | | => new( nameof( UnexpectedError ), DatabaseError, "حدث خطأ غير متوقع.", "An unexpected error occurred.", Severit |
| | 32 | 80 | | additionalData ); |
| | | 81 | | } |