Using LINQ specifications in the data access layer

The specification pattern is a way to encapsulate query criteria inside aptly named business rule objects, called specifications. A specification has a single purpose. It should answer whether an entity of some type satisfies the conditions or criteria for a specific business rule or not.

In this recipe, we'll show you how to set up and use the specification pattern with the NHibernate repository and LINQ expressions.

Getting ready

To complete this recipe we will need a LinqSpecs library. The documentation and source code can be found at http://linqspecs.codeplex.com.

Complete the Setting up an NHibernate repository recipe.

How to do it…

  1. Install LinqSpecs using the NuGet Package Manager console by executing ...

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.