Skip to content

Instantly share code, notes, and snippets.

@MiniverCheevy
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiniverCheevy/8af032691b8afa26a49b to your computer and use it in GitHub Desktop.
Save MiniverCheevy/8af032691b8afa26a49b to your computer and use it in GitHub Desktop.
DbEntityValidationExceptionTranlator
public class DbEntityValidationExceptionTranlator: ExceptionTranslation
{
protected override bool TranslateException(Exception exception, IResponse response)
{
var dbException = exception as DbEntityValidationException;
if (dbException == null)
return false;
response.Message = dbException.Message;
foreach (var item in dbException.EntityValidationErrors)
{
foreach (var error in item.ValidationErrors)
{
response.Details.Add(error.PropertyName, error.ErrorMessage);
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment