Visual Studio .NET Code Snippets:
Workaround the Linq Timestamp Concurrency Bug

This is a pretty serious bug and it's been around a long time but never been fixed as far as I can tell. None of the posted workarounds appears to fully work either.

On LINQ to SQL, Concurrency and Timestamps

LINQ update fails for concurrency issue

Resolving a change conflict with KeepCurrentValues mode causes an exception when a timestamp property exists

My Workaround:

  1. Change Timestamp field on .dbml to Auto-Sync on insert

  2. After you submit changes, manually reload timestamps from database. Example (I set my partial classes to inherit from a BaseBusiness class that manages validation errors, and maintains a 'Dirty' flag.

    db.SubmitChanges(ConflictMode.ContinueOnConflict);

    foreach (var t in userLawyerLinks)

    if (o.IsDirty) o.ModifiedStamp = (from x in db.User_Lawyer_Links where x.User_Lawyer_Link_GUID == o.User_Lawyer_Link_GUID select x.ModifiedStamp).Single();