Using LINQ to NHibernate

Since version 3.0 NHibernate has included a LINQ provider. In this recipe, we'll show you how to execute LINQ queries with NHibernate.

Getting ready

Complete the Getting Ready section given at the beginning of this chapter.

How to do it…

  1. Add a new folder named QueryByLinq to the project.
  2. Add a new class named LinqQueries to the folder:
    using System.Collections.Generic; using System.Linq; using NH4CookbookHelpers.Queries; using NH4CookbookHelpers.Queries.Model; using NHibernate; using NHibernate.Linq; namespace QueryRecipes.QueryByLinq { public class LinqQueries : IQueries { private readonly ISession _session; public LinqQueries(ISession session) { _session = session; } public IEnumerable<Movie> GetMoviesDirectedBy( string directorName) ...

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.