I noticed that if I have a plugin running on an entity and I run two updates on the same instance of the entity the updates will run in parallel if there are no pre entity images, but if there are pre entity images they will run in sequence. Ie. if I have a plugin that takes 10 seconds to run:
Pre entity image registered:
T) A presses save
T + 1) B presses save
T + 10) A's update finishes
T + 20) B's update finishes with the pre entity image containing values populated after A's update finished
Pre entity image not registered:
T) A presses save
T + 1) B presses save
T + 10) A's update finishes
T + 11) B's update finishes
Looking at the sys.dm_tran_locks management view in SQL server I can see that an application lock is taken when the pre entity image is registered but no application lock is taken otherwise. Is this behavior documented anywhere? I have a situation where it would be very useful for me to be able to guarantee that updates on the same instance of an entity are always run in sequence rather than in parallel.