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 to NHibernate

NHibernate 3.0 includes a new LINQ provider. In this recipe, I'll show you how to execute LINQ queries with NHibernate.

How to do it...

  1. Complete the steps in the introduction at the beginning of this chapter.
  2. Add the following methods to the Queries class:
    public IEnumerable<Movie> GetMoviesDirectedBy( string directorName) { var query = from m in _session.Query<Movie>() where m.Director == directorName select m; return query.ToList(); } public IEnumerable<Movie> GetMoviesWith( string actorName) { var query = from m in _session.Query<Movie>() where m.Actors.Any( ar => ar.Actor == actorName) select m; return query.ToList(); } public Book GetBookByISBN(string isbn) { var query = from b in _session.Query<Book>() where b.ISBN == ...

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