Using QueryOver
NHibernate 3.0 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, we'll show you the QueryOver
syntax for the criteria queries from our last recipe.
Getting ready
Complete the Getting Ready instructions at the beginning of this chapter.
How to do it…
Add a new folder named
QueryByQueryOver
to the project.Add a new class named
QueryOverQueries
to the folder:using System.Collections.Generic; using NH4CookbookHelpers.Queries; using NH4CookbookHelpers.Queries.Model; using NHibernate; namespace QueryRecipes.QueryByQueryOver { public class QueryOverQueries : IQueries { private readonly ISession _session; public QueryOverQueries(ISession session) { _session = session; } } }
Add the following method to the
QueryOverQueries
class:public IEnumerable<Movie> GetMoviesDirectedBy...