Handling Optimistic Concurrency

Of course, the ADO.NET Entity Framework provides the ability to handle optimistic concurrency exceptions. You need to intercept eventual System.Data.Entity.Infrastructure.DbUpdateConcurrencyException instances. When intercepted, you need to determine what entries were not updated in the database by using the Entries property of the exception instance and make an appropriate decision. The following code revisits the UpdateProduct custom method described in the “Updating Entities” subsection, providing the first example:

Sub UpdateProduct()    Try        Dim check = northwindContext.Products.                    Single(Function(p) p.                    ProductName = "Italian spaghetti") ...

Get Visual Basic 2015 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.