I’ve got a Windows Service and a ASP.NET MVC 2 application that both connect to the same database using Fluent nHibernate (nHibernate 3).
One of the entities (called Profile) has a string property that contains the url to an image.
This property randomly looses it’s value and I can’t figure out what is causing it. The users update this via the MVC front end but my gut feeling is the windows service is overwriting its value with an older instance of the entity (the windows service updates another property on the same class).
Can someone please explain / help with how to either debug this or the best way to manage the concurrency, I’ve read up on the subject but am getting confused about optimistic and pessimistic locking in nHibernate.
Kind regards
Sam
An option could be using
<version/>with Optimistic Locking. With this you have no performance drawback, and you are sure the result is what you want. If one agent try to update a record another agent updated before, that agent will fail. Of course you should handle somehow that exception, but at least you don’t have dirty updates/reads.To use
<version/>tou should add a column in your table to mantain the version. In standard NH mapping the documentation is: