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

Setting up an NHibernate Repository

Many developers prefer the repository pattern over data access objects. In this recipe, I'll show you how to set up the repository pattern with NHibernate.

Getting ready

Set up the Eg.Core project with the model and mappings from Chapter 1.

How to do it...

  1. Create a new, empty class library project named Eg.Core.Data.
  2. Add a reference to Eg.Core project in Chapter 1.
  3. Add the following IRepository interface:
    public interface IRepository<T>: IEnumerable<T> 
    where T : Entity 
    { 
      void Add(T item);
      bool Contains(T item);
      int Count { get; }
      bool Remove(T item);
    }
  4. Create a new, empty class library project named Eg.Core.Data.Impl.
  5. Add references to Eg.Core and Eg.Core.Data
  6. Add a new abstract class named NHibernateBase using 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