Handling Optimistic Concurrency

Of course, the ADO.NET Entity Framework provides the ability to handle optimistic concurrency exceptions. Basically you need to intercept eventual System.Data.OptimisticConcurrencyException instances. When intercepted, you need to invoke the ObjectContext.Refresh method that allows solving the concurrency problem. The following code revisits the AddProduct custom method described in the “Adding Entities” subsection:

image

If an OptmisticConcurrencyException is thrown, first you need to invoke the ObjectContext.Refresh mode that is responsible for solving concurrency problems. It receives two arguments: The first one is ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.