O'Reilly logo

NHibernate 3 Beginner's Guide by Gabriel N. Schenker

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

Time for action – Creating a base entity

First, we want to implement a base class for all types of entities. This class implements the logic around the ID which is common for all types of entities.

  1. Add a new class to the folder Domain of the project and call it Entity. Make the class abstract and generic in T. Your code should look similar to the following code snippet:
    using System;
    
    namespace OrderingSystem.Domain
    {
      public abstract class Entity<T> where T : Entity<T>
      { }
    }
  2. Add an auto-property ID of type Guid to the class. Make the setter of the property private. This will be our unique identifier for the entity. For a new entity, the ID will automatically have assigned the value of Guid.Empty, as shown in the following line of code:
    public Guid ...

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