How to: Specify When Concurrency Exceptions are Thrown (LINQ to SQL)
In LINQ to SQL, a ChangeConflictException exception is thrown when objects do not update because of optimistic concurrency conflicts. For more information, see Optimistic Concurrency Overview (LINQ to SQL).
Before you submit your changes to the database, you can specify when concurrency exceptions should be thrown:
Throw the exception at the first failure (FailOnFirstConflict).
Finish all update tries, accumulate all failures, and report the accumulated failures in the exception (ContinueOnConflict).
When thrown, the ChangeConflictException exception provides access to a ChangeConflictCollection collection. This collection provides details for each conflict (mapped to a single failed update try), including access to the MemberConflicts collection. Each member conflict maps to a single member in the update that failed the concurrency check.
The following code shows examples of both values.
Dim db As New Northwnd("...") ' Create, update, delete code. db.SubmitChanges(ConflictMode.FailOnFirstConflict) ' or db.SubmitChanges(ConflictMode.ContinueOnConflict)
Northwnd db = new Northwnd("..."); // Create, update, delete code. db.SubmitChanges(ConflictMode.FailOnFirstConflict); // or db.SubmitChanges(ConflictMode.ContinueOnConflict);