views:

71

answers:

1

Hi all,

As a apprentice for web development, I have no clue of preventing dirty write for web forums. Is there any food for thought? Thanks in advance!

I'm working on ASP.NET MVC and Entity Framework.

Okay, sorry for misleading. The dirty write here means overwrite changes of another person in the database. While using a Optimistic Concurrency.

+2  A: 

To do optimistic concurrency in the EF, you:

  1. Add or select a field to use for optimistic concurrency control. We use a TIMESTAMP.
  2. In the EF designer, change the ConcurrencyMode to Fixed for this property.
  3. Serialize the "old" value of the field to a hidden field on the form.
  4. Deserialize the "old" value when the form is submitted, and add it to the entity you're updating.

The EF will throw OptimisticConcurrencyException when the stored value doesn't match the old value during an update.

Craig Stuntz