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

Using LINQ Specifications in the data access layer

With the completion of LINQ to NHibernate for NHibernate 3.0, we can easily implement the specification pattern. In this recipe, I'll show you how to set up and use the specification pattern with the NHibernate repository.

Getting ready

Download the LinqSpecs library from http://linqspecs.codeplex.com. Copy LinqSpecs.dll from the Downloads folder to your solution's libs folder.

Complete the Setting up an NHibernate Repository recipe.

How to do it...

  1. In Eg.Core.Data and Eg.Core.Data.Impl, add a reference to LinqSpecs.dll.
  2. Add these two methods to the IRepository interface.
    IEnumerable<T> FindAll(Specification<T> specification);
    T FindOne(Specification<T> specification);
  3. Add the following three methods ...

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