1. This is incredibly useful and is making working threw Validation exceptions a LOT more straight forward.

    VipX1 Dev.

  2. Great, thanks a lot.


  3. What if I want those Details to reach the client?

    I have EF context exposed through a WCF Data Service and I still get the formal ( no-details) DataServiceRequestException “An error occurred while processing this request”. What to do?


  4. This helped me out so much with a frustrating issue, thanks!


  5. Thanks
    useful 🙂


  6. Thank mate. That was awsome.

    Marian Pintilie

  7. Nice one Martin
    I’d been doing this every time I called Context.SaveChanges(), this makes it so simple.

    Thanks again.

    Mark Harby

  8. I’ll just say that, thank you very much for bring me this information. I usually don´t leave replies but now you give me an excellent tool for my project.

    Thank you again, I’m gonna put this webpage as the link for copyright into my code.


    Rodrigo Uzcátegui

  9. Excellent..
    Thanks very much for this blog.. very very helpful.
    It saved me hell lot of time.



  10. […] entities. See ‘EntityValidationErrors’ property for more details” and found a blog post to follow which provided me the details I needed when debugging to solve the […]

    Template, Registration and Login | Devin W.C. Ryan

  11. Below is a version that includes all the necessary includes:

    using System.Data.Entity;
    using System.Data.Entity.Validation;
    using System.Linq;

    namespace MyNamespace

    public partial class MyContext : DbContext
    // Override base SaveChanges to expand out validation errors so client gets an actually helpful message
    public override int SaveChanges()
    return base.SaveChanges();
    catch (DbEntityValidationException ex)
    // Retrieve the error messages as a list of strings.
    var errorMessages = ex.EntityValidationErrors
    .SelectMany(x => x.ValidationErrors)
    .Select(x => x.ErrorMessage);

    // Join the list to a single string.
    var fullErrorMessage = string.Join(“; “, errorMessages);

    // Combine the original exception message with the new one.
    var exceptionMessage = string.Concat(ex.Message, ” The validation errors are: “, fullErrorMessage);

    // Throw a new DbEntityValidationException with the improved exception message.
    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);


  12. Mastch… Liked it.. Thanx…


  13. What if I am making use of code first?

    Sunny Okoro

    • It works the same way!


  14. Thanks so much !
    for almost a week I have been through that error.

    Mohamed Moka

  15. thanks a lot .. it is perfectly useful


  16. very useful i found the solution . now i’m very happy..


  17. Awesome!


  18. thanks


Comments are closed.