O'Reilly logo

NHibernate 3.0 Cookbook by Jason Dentler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling versioning and concurrency

For any multiuser transactional system, you must decide between optimistic and pessimistic concurrency to handle concurrent updates and versioning issues. In this recipe, I'll show you how to properly set up versioning and optimistic concurrency with NHibernate.

Getting ready

Complete all the previous recipes including Setting up a base entity class.

How to do it...

  1. In the Entity base class, add a Version property, as shown in the following code:
    public abstract class Entity<TId>
    {
    
      public virtual TId Id { get; protected set; }
      protected virtual int Version { get; set; }
    
      public override bool Equals(object obj)
      {
        return Equals(obj as Entity<TId>);
      }
  2. In the Product mapping, add the version element as shown in the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required