Handling Optimistic Concurrency

Optimistic concurrency is a scenario in which multiple clients send changes to the database simultaneously. LINQ to SQL allows resolving optimistic concurrency with the DataContext.ChangeConflicts.ResolveAll method. Such method receives an argument that is an enumeration of type System.Data.Linq.RefreshMode and allows resolving the exception with one of the enumeration members summarized in Table 25.1.

Table 25.1 RefreshMode Enumeration Members

image

The following is an example of handling optimistic concurrency, providing a revisited version of the previously utilized SaveChanges custom method:

Notice first how a

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.