Skip to content

Commit

Permalink
Remove extra check for entries as DbUpdateException no longer does th…
Browse files Browse the repository at this point in the history
…e check
  • Loading branch information
Giorgi committed Nov 25, 2024
1 parent fb4b298 commit 98e1466
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions EntityFramework.Exceptions.Common/ExceptionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,13 @@ static class ExceptionFactory
{
internal static Exception Create<T>(ExceptionProcessorInterceptor<T>.DatabaseError error, Exception exception, IReadOnlyList<EntityEntry> entries) where T : DbException
{
if (entries?.Count > 0)
{
return error switch
{
ExceptionProcessorInterceptor<T>.DatabaseError.CannotInsertNull => new CannotInsertNullException( "Cannot insert null", exception.InnerException, entries),
ExceptionProcessorInterceptor<T>.DatabaseError.MaxLength => new MaxLengthExceededException( "Maximum length exceeded", exception.InnerException, entries),
ExceptionProcessorInterceptor<T>.DatabaseError.NumericOverflow => new NumericOverflowException( "Numeric overflow", exception.InnerException, entries),
ExceptionProcessorInterceptor<T>.DatabaseError.ReferenceConstraint => new ReferenceConstraintException( "Reference constraint violation", exception.InnerException, entries),
ExceptionProcessorInterceptor<T>.DatabaseError.UniqueConstraint => new UniqueConstraintException( "Unique constraint violation", exception.InnerException, entries),
_ => null,
};
}

return error switch
{
ExceptionProcessorInterceptor<T>.DatabaseError.CannotInsertNull => new CannotInsertNullException("Cannot insert null", exception.InnerException),
ExceptionProcessorInterceptor<T>.DatabaseError.MaxLength => new MaxLengthExceededException("Maximum length exceeded", exception.InnerException),
ExceptionProcessorInterceptor<T>.DatabaseError.NumericOverflow => new NumericOverflowException("Numeric overflow", exception.InnerException),
ExceptionProcessorInterceptor<T>.DatabaseError.ReferenceConstraint => new ReferenceConstraintException("Reference constraint violation", exception.InnerException),
ExceptionProcessorInterceptor<T>.DatabaseError.UniqueConstraint => new UniqueConstraintException("Unique constraint violation", exception.InnerException),
ExceptionProcessorInterceptor<T>.DatabaseError.CannotInsertNull => new CannotInsertNullException("Cannot insert null", exception.InnerException, entries),
ExceptionProcessorInterceptor<T>.DatabaseError.MaxLength => new MaxLengthExceededException("Maximum length exceeded", exception.InnerException, entries),
ExceptionProcessorInterceptor<T>.DatabaseError.NumericOverflow => new NumericOverflowException("Numeric overflow", exception.InnerException, entries),
ExceptionProcessorInterceptor<T>.DatabaseError.ReferenceConstraint => new ReferenceConstraintException("Reference constraint violation", exception.InnerException, entries),
ExceptionProcessorInterceptor<T>.DatabaseError.UniqueConstraint => new UniqueConstraintException("Unique constraint violation", exception.InnerException, entries),
_ => null,
};
}
Expand Down

0 comments on commit 98e1466

Please sign in to comment.