Query in NHIBERNATE is an object-oriented query language! Features such as inheritance, polymorphism and association. It looks very similar to SQL, but only the table name is replaced with the object name, and the field replaces the property.
NHibernate provides an interface iQuery to set query statements, parameters, etc. The implementation class for this interface is queryimpl. Like criteriaImpl, you cannot create directly outside the NHibernate program, you can only get a IQuery interface through the session.
Some methods of the iQuery interface are listed here:
SetMaxResults: Set the maximum number of results returned, available for paging;
SetFirstResult: Set the position returned by the first object, available for paging;
SetTimeout: Set the timeout value of the operation, this value will be passed to the idbcommand object;
ENUMERABLE: Returns the enumeration object of the query;
List: Returns the collection of objects;
SetParameter: Set the value and type of the parameters in the query statement.
Let's take a few simple examples:
1. Return to all members:
String query = "from member";
IList meMber = session.createQuery (query) .list ();
2. Return to the member starting with B:
String query = "from member m where m.name like b%";
IList members = session.createQuery (query) .list ();
3. Return to all member IDs and names:
String query = "SELECT M.MEMBERID, M.NAME from MEMBER M";
IList members = session.createQuery (query) .list ();
Note: MemberID, name here is the properties of the Member object.
The return is not a collection of MEMBERS objects, but a collection of one-dimensional array,
Among them, Array [0] is MEMBERID, Array [1] is Name
4. Return to the total number of members:
String query = "SELECT COUNT (*) from member";
IENUMERATOR E = session.createQuery (query) .enumerable (). Getenumerator ();
E.MOVENEXT;
INT ROWCOUNT = (int);
5. Returns the member string query = "from member" of the specified (from 20-40); ilist minutes = session.createQuery (query) .SetFirstResult (20) .setMaxResults (20) .list () HQL also supports statistical functions, For more example, please refer to the relevant documentation.
For SQL Server, the data positioning is used by iDataReader to the firstResult, then take the MaxResults record.