An object-oriented representation of a NHibernate query.

Namespace: NHibernate
Assembly: NHibernate (in NHibernate.dll) Version: 3.2.0.4000 (3.2.0.4000)

Syntax

C#
public interface IQuery
Visual Basic
Public Interface IQuery
Visual C++
public interface class IQuery

Remarks

An IQuery instance is obtained by calling CreateQuery(String). Key features of this interface include:
  • Paging: A particular page of the result set may be selected by calling SetMaxResults(Int32), SetFirstResult(Int32). The generated SQL depends on the capabilities of the Dialect. Some Dialects are for databases that have built in paging (LIMIT) and those capabilities will be used to limit the number of records returned by the SQL statement. If the database does not support LIMITs then all of the records will be returned, but the objects created will be limited to the specific results requested.
  • Named parameters
  • Ability to return 'read-only' entities

Named query parameters are tokens of the form :name in the query string. For example, a value is bound to the Int32 parameter :foo by calling:

CopyC#
SetParameter("foo", foo, NHibernateUtil.Int32);
A name may appear multiple times in the query string.

Unnamed parameters ? are also supported. To bind a value to an unnamed parameter use a Set method that accepts an Int32 positional argument - numbered from zero.

You may not mix and match unnamed parameters and named parameters in the same query.

Queries are executed by calling List()()()() or Enumerable()()()(). A query may be re-executed by subsequent invocations. Its lifespan is, however, bounded by the lifespan of the ISession that created it.

Implementors are not intended to be threadsafe.

See Also