Skip to content

Instantly share code, notes, and snippets.

@roboter
Created June 1, 2015 10:34
Show Gist options
  • Save roboter/0671ee1c4f7be7560864 to your computer and use it in GitHub Desktop.
Save roboter/0671ee1c4f7be7560864 to your computer and use it in GitHub Desktop.
try
{
// Your code...
// Could also be before try if you know the exception occurs in SaveChanges
context.SaveChanges();
}
catch (DbEntityValidationException e)
{
foreach (var eve in e.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
}
}
t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment