public async Task SaveAsync()
        {
            try
            {
                await _phoneBookDataContext.SaveChangesAsync();
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                IEnumerable <string> errorMessages = ex.EntityValidationErrors
                                                     .SelectMany(x => x.ValidationErrors)
                                                     .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                string fullErrorMessage = string.Join(" ", errorMessages);

                // Combine the original exception message with the new one.
                string exceptionMessage = string.Concat(ex.Message, "The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }
예제 #2
0
        public async Task <OperationResult> CompleteAsync()
        {
            await context.SaveChangesAsync();

            return(new OperationResult(true, "Request completed successfully"));
        }