NHibernate + ViewModel + MVC + Optimistic Lock

Ok, we have the following scenario, but how are you Optimistic lock

we have customer class

  • Name
  • The address
  • Version

Version is a collision variable (int), which, when editing a line, the version will increase by 1.

Now we have Martin, who opens Customer 129, since in the model of representation, the model object is smoothed in Model View, and then goes to the client’s editing screen.

David at this time also opens Client 129 for editing, changes the name and saves.

Martin, who was still editing the client (now the old version), goes to save his changes, at this point I hope you see a blocking error

Question: how do you handle optimistic locking with NH (using FluentNHibernate for comparisons) would you do

  • need to click verion number in ViewModel? then when it was sent with the update, load the current Model object and check the version number
  • Or is this the best way (I know NH will do version control if I download, edit and update in the same session)

one additional thing, this script will be used on a farm, not for cache sharing

thank you very much in advance

+3
source share
1 answer

This is essentially a standalone lock that NHibernate cannot handle.

What you need to do is something like:

Change request:

  • Download item
  • Push ViewModel ( )
  • ....

:

  • ()
    • /
    • else ..
+2

Source: https://habr.com/ru/post/1779487/


All Articles