EasyRepository/GenericUnitOfWork.cs
/// <summary>
///   Handles the provided DbEntityValidationException and iterates through validation errors
///   to rethrow a more detailed exception.
/// </summary>
/// <param name="entityValidationException">
///   The db entity validation exception being handled.
/// </param>
/// <exception cref="Exception">
///   Exception thrown after extracting validation errors from the provided exception.
/// </exception>
Handles the provided DbEntityValidationException and iterates through validation errors
to rethrow a more detailed exception.
Handles the provided DbEntityValidationException and iterates through validation errors to rethrow a more detailed exception .
private void HandleDbEntityValidationException(DbEntityValidationException entityValidationException)
        {
            var sb = new StringBuilder();
            foreach (var failure in entityValidationException.EntityValidationErrors)
            {
                sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                foreach (var error in failure.ValidationErrors)
                {
                    sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                    sb.AppendLine();
                }
            }
            throw new Exception(sb.ToString(), entityValidationException);
        }
private void HandleDbEntityValidationException ( DbEntityValidationException entityValidationException ) { var sb = new StringBuilder ( ) ; foreach ( var failure in entityValidationException . EntityValidationErrors ) { sb . AppendFormat ( " \n " , failure . Entry . Entity . GetType ( ) ) ; foreach ( var error in failure . ValidationErrors ) { sb . AppendFormat ( " " , error . PropertyName , error . ErrorMessage ) ; sb . AppendLine ( ) ; } } throw new Exception ( sb . ToString ( ) , entityValidationException ) ; }
Handles the provided DbEntityValidationException and iterates through validation errors
to rethrow a more detailed exception.
Handles the provided DbEntityValidationException and iterates through validation errors to rethrow a more detailed exception .
Exception thrown after extracting validation errors from the provided exception.
Exception thrown after extracting validation errors from the provided exception .
entityValidationException
DbEntityValidationException
The db entity validation exception being handled.
The db entity validation exception being handled .