O'Reilly logo

Working with NHibernate 3.0 by Benjamin Perkins

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

4

Using LINQ to NHibernate

In the previous chapter, the ICritera API, a programmatic method of data retrieval, was discussed. Recall that the ICriteria interface contains the QueryOver API, which is a type-safe compile-time wrapper for the ICriteria API. It is possible to use lambda expressions in both QueryOver and LINQ to NHibernate. In this chapter, you will learn the following:

  • Working with LINQ to NHibernate
  • Using LINQ to NHibernate with lambda expressions
  • Implementing paging using LINQ to NHibernate
  • Understanding aggregate database functions with LINQ to NHibernate

INTRODUCTION

The release of NHibernate 3.0 included LINQ capabilities for use with NHibernate. LINQ is a very powerful querying tool that exists for objects, SQL, XML, and many other extensions for querying information sources. The LINQ to NHibernate provider implements most of the .NET LINQ operators found in the System.Linq namespace. Table 4-1 shows the operator types and execution method(s) provided with the LINQ to NHibernate provider.

TABLE 4-1:LINQ Operators

OPERATOR EXECUTION METHODS
Aggregates Count, Sum, Min, Max, and Average
Conversion ToArray, ToList, ToDictionary, and OfType
Element First, FirstOrDefault, ElementAt
Generation Range, and Repeat
Grouping GroupBy
Join Cross, Group, and Left Outer
Ordering OrderBy, OrderByDescending, ThenBy, ThenByDescending, and Reverse
Partitioning Take, Skip, TakeWhile, and SkipWhile
Projection Select and SelectMany
Quantifiers Any and ...

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