Exception Handling with Entity Framework context.SaveChanges()

3 posts, 0 answers
  1. Vandana
    Vandana avatar
    3 posts
    Member since:
    Jul 2010

    Posted 16 Jul 2010 Link to this post

    We are making multiple updates to our Entity Framework object context based on the changes made to the UI. For e.g.

    If we have an Employee entity in our context we are coding in the following manner

     

     

    using (TestDBEntities testDBContext = new TestDBEntities())

    {

     // Code to add a new employee

    // Code to update an existing employee

    // Code to delete an employee

    // Save changes to the database

    testDBContext.SaveChanges();

    }

    In this scenario we want to trap all the possible exceptions that can result in during the various add, update, delete operations. Presently we have observed that SaveChanges() throws only one exception at a time like OptimisticConcurreny exception / UpdateException and aborts the transaction. Is there any in-built mechanism in EF where in we can get all possible exceptions generated during SaveChanges so that all errors can be displayed to the user at the same time and then abort the transaction?

  2. Hugo Augusto
    Hugo Augusto avatar
    55 posts
    Member since:
    Jul 2004

    Posted 20 Jul 2010 Link to this post

    Hi Vandana,

    got any answer yet?
  3. DevCraft banner
  4. Vandana
    Vandana avatar
    3 posts
    Member since:
    Jul 2010

    Posted 20 Jul 2010 Link to this post

    No answer as of now
Back to Top