try { db.SaveChanges(); }
catch (DbEntityValidationException ex)
{
StringBuilder errors = new StringBuilder();
IEnumerable<DbEntityValidationResult> validationResult = ex.EntityValidationErrors;
foreach (DbEntityValidationResult result in validationResult)
{
ICollection<DbValidationError> validationError = result.ValidationErrors;
foreach (DbValidationError err in validationError)
{
errors.Append(err.PropertyName + ":" + err.ErrorMessage + "
");
}
}
Console.WriteLine(errors.ToString());
}