Created
September 4, 2014 12:55
-
-
Save ycaroafonso/73d241d75c9a22f6ecbf to your computer and use it in GitHub Desktop.
Exception entityframework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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