To use ROWVERSION in LINQ or not?
Posted on 2008-11-17
In .NET 3.5, when I want to update and object and save its results, I query it from the database, assign new values and SubmitChanges(). This means I can overwrite someone else's changes. As an example, each "T" means time. DataContexts are created in a using statement:
T1: PersonA queries and loads ID=49 of a Person object and assigns new address without SubmitChanges().
T2: PersonB queries ID=49 of a Person object, updates and SubmitChanges().
T3: PersonA queries ID=49 of a Person, updates with values from T1 and SubmitChanges().
In the example, PersonA wrote over PersonB's changes. Although not entirely if only one or two properties were being updated. Everything is fine if PersonB only changed PhoneNumber. If I go with a ROWVERSION and keep a DataContext around inside the Person object, what will happen in this situation?
Not using ROWVERSION is the simpler solution but I will always potentially overwrite someone's changes in the above scenario. What is the best way to handle this case?