It's often important to handle scenarios where two or more clients may try to work with the same entities, concurrently. In Chapter 2, Models and Mappings, in section: Handling versioning and concurrency we discussed how to handle that using versioning and optimistic concurrency. A more aggressive approach is to use pessimistic concurrency, where specific rows in the database are explicitly locked for certain operations. Many DBMSes, such as SQL Server, has a good support for this and in this recipe we'll show how NHibernate can use that functionality.
Follow the Getting ready step in the Save entities to the database recipe in this chapter.
Since this recipe requires specific database support, you can't run it using the SQLite database, which is the default in NH4CookbookHelpers
. Reconfigure the recipe runner by setting the RecipeLoader.DefaultConfiguration
property or simply override the Configure method in the Recipe class...