This is a migrated thread and some comments may be shown as answers.

Exception Handling with Entity Framework context.SaveChanges()

2 Answers 147 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vandana
Top achievements
Rank 1
Vandana asked on 16 Jul 2010, 05:05 AM

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 Answers, 1 is accepted

Sort by
0
Hugo Augusto
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 20 Jul 2010, 04:58 PM
Hi Vandana,

got any answer yet?
0
Vandana
Top achievements
Rank 1
answered on 21 Jul 2010, 04:44 AM
No answer as of now
Tags
LINQ (LINQ specific questions)
Asked by
Vandana
Top achievements
Rank 1
Answers by
Hugo Augusto
Top achievements
Rank 2
Iron
Veteran
Iron
Vandana
Top achievements
Rank 1
Share this question
or