Last active
August 29, 2015 14:25
-
-
Save rrrhys/2798a5f2591af18bd5a9 to your computer and use it in GitHub Desktop.
Wrap your Entities class.
This file contains 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
public class FormattedDbEntityValidationException : Exception | |
{ | |
public FormattedDbEntityValidationException(DbEntityValidationException innerException) : | |
base(null, innerException) | |
{ | |
} | |
public override string Message | |
{ | |
get | |
{ | |
var innerException = InnerException as DbEntityValidationException; | |
if (innerException != null) | |
{ | |
StringBuilder sb = new StringBuilder(); | |
sb.AppendLine(); | |
sb.AppendLine(); | |
foreach (var eve in innerException.EntityValidationErrors) | |
{ | |
sb.AppendLine(string.Format("- Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", | |
eve.Entry.Entity.GetType().FullName, eve.Entry.State)); | |
foreach (var ve in eve.ValidationErrors) | |
{ | |
sb.AppendLine(string.Format("-- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"", | |
ve.PropertyName, | |
eve.Entry.CurrentValues.GetValue<object>(ve.PropertyName), | |
ve.ErrorMessage)); | |
} | |
} | |
sb.AppendLine(); | |
return sb.ToString(); | |
} | |
return base.Message; | |
} | |
} | |
} |
This file contains 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
public class WrappedimeclockEntities : TimeclockEntities | |
{ | |
public override int SaveChanges() | |
{ | |
try | |
{ | |
return base.SaveChanges(); | |
} | |
catch (DbEntityValidationException e) | |
{ | |
var newException = new FormattedDbEntityValidationException(e); | |
throw newException; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment