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

3

Using ICriteria

In the previous chapter you learned how the Hibernate Query Language (HQL) works and how to implement most of the APIs that make up the library. Most important, you learned how to combine queries so that fewer round-trips can be made to the database, thereby improving the program's performance. This chapter covers using ICriteria, which is a more method-based query API versus the SQL-like queries of IQuery. In this chapter, you learn about the following:

  • CreateCriteria, CreateMultiCriteria, DetachedCriteria, QueryOver, and Futures
  • Implementing paging
  • Lambda expressions
  • FetchMode, Restrictions, and data transfer objects (DTOs)

INTRODUCTION

The ICriteria interface is a feature-rich, method-based query API. When I first started using NHibernate, I chose to use ICriteria. As a programmer, the implementation of ICritera seemed more programmatic than HQL — meaning that instead of using dot (.) notation in a string, ICriteria provides methods, classes, and properties for creating the query. A large number of ICriteria methods are accessible via the Session to execute a query against the database, and pulling the methods and properties together seems almost intuitive.

Figure 3-1 provides a graphical representation of the methods and their corresponding execution methods for using the ICriteria interface, which implements the same functionality described in the previous chapter for IQuery. This chapter describes these methods and provides examples demonstrating how ...

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