Skip to content

Instantly share code, notes, and snippets.

@ycaroafonso
Created September 4, 2014 12:55
Show Gist options
  • Select an option

  • Save ycaroafonso/73d241d75c9a22f6ecbf to your computer and use it in GitHub Desktop.

Select an option

Save ycaroafonso/73d241d75c9a22f6ecbf to your computer and use it in GitHub Desktop.
Exception entityframework
catch (DbEntityValidationException e)
{
string erro = string.Empty;
foreach (var eve in e.EntityValidationErrors)
{
erro += (string.Format("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)
{
erro += (string.Format("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage));
}
}
throw new Exception(erro);
}
catch (DbUpdateException e)
{
//SqlException s = e.InnerException.InnerException as SqlException;
throw new Exception(e.InnerException.InnerException.Message);
}
catch (Exception)
{
throw;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment