Entity Framework – Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details.

This is how Visual Studio tells you that something went wrong while updating your entity.
Simple solution would be to catch System.Data.Entity.Validation.DbEntityValidationException and iterate through EntityValidationErrors collection.

try
{
	return _context.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbvEx)
{
    List<string> errors = new List<string>();
    foreach (var validationErrors in dbvEx.EntityValidationErrors)
    {
        foreach (var validationError in validationErrors.ValidationErrors)
        {
            errors.Add(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
        }
    }
    return 0;
}

errors

Leave a Reply

Your email address will not be published. Required fields are marked *