EF Code First: How do I see 'EntityValidationErrors' property from the nuget package console?
Add-Migration "remigrate" ; Update-Database;
///
/// Wrapper for SaveChanges adding the Validation Messages to the generated exception
///
/// The context.
private void SaveChanges(DbContext context)
{
try
{
context.SaveChanges();
}
catch (DbEntityValidationException ex)
{
StringBuilder sb = new StringBuilder();
foreach (var failure in ex.EntityValidationErrors)
{
sb.AppendFormat("{0} failed validationn", failure.Entry.Entity.GetType());
foreach (var error in failure.ValidationErrors)
{
sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
sb.AppendLine();
}
}
throw new DbEntityValidationException("Entity Validation Failed - errors follow:n" + sb.ToString());
}
}