Concurrency Questions

time to read 1 min | 168 words

I was asked a question today, and I'm not sure what the answer is. The issue is with optimistic concurrency on the web. I got an edit page that allows a user to edit a page. I want to throw a concurrency exception if a second user has changed the object while the first user was editing it.

The issue is that when I get the values of the form back when the user is finished editing, I no longer know what version of the object the user has edited. It looks like I would need to store the version of the object (most likely a SQL Server Row Version) in the form as well, and then get the object from NHibernate, set the version property of the object (and all the rest of the fields), and then try to save, to see if there was a concurrency violation.

Any other ideas that I have not thought of?