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 QueryOver

NHibernate 3.0 has added a new fluent syntax to criteria queries. Although it's not an actual LINQ provider, it does bring the familiar lambda syntax to criteria queries, eliminating the magic strings problem. In this recipe, I'll show you the new QueryOver syntax for the criteria queries from our last recipe.

How to do it...

  1. Complete the setup steps in the introduction at the beginning of this chapter.
  2. In the Queries class, add the following method:
    public IEnumerable<Movie> GetMoviesDirectedBy(string directorName)
    {
      return _session.QueryOver<Movie>()
        .Where(m => m.Director == directorName)
        .List();
    }
  3. In the Queries class, add the following method to query for movies by actor's name:
    public IEnumerable<Movie> GetMoviesWith(string actorName) ...

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