Handling versioning and concurrency

For any multiuser transactional system, you must decide how to handle concurrent updates and possible versioning issues. In this recipe, we will show you how to set up versioning and optimistic concurrency with NHibernate.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a new folder named Versioning to the MappingRecipes project.
  2. Add a new class named VersionedProduct to the folder:
    public class VersionedProduct
    {
        public virtual int Id { get; protected set; }
        public virtual int Version { get; protected set; }
        public virtual string Name { get; set; }public virtual string Description { get; set; }}
  3. Add an embedded mapping named VersionProduct.hbm.xml:
    <?xml version="1.0" ...

Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.