Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EF Code First: How do I see 'EntityValidationErrors' property from the nuget package console?
- Add-Migration "remigrate" ; Update-Database;
- /// <summary>
- /// Wrapper for SaveChanges adding the Validation Messages to the generated exception
- /// </summary>
- /// <param name="context">The context.</param>
- 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());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement