Simple use of nhib.pdf Data Query

Source: Internet
Author: User
1. Return all members:
String query = "from member ";
Ilist member = session. createquery (query). List ();

2. Return members starting with B:
String query = "from member m where M. name like B % ";
Ilist members = session. createquery (query). List ();

3. Return all member IDs and names:
String query = "select M. memberid, M. name from member M ";
Ilist members = session. createquery (query). List ();
Note: The memberid and name here are the attributes of the member object.
The returned result is not a set of Members objects, but a set of one-dimensional arrays,
Where array [0] Is memberid, array [1] is name

4. Total number of returned Members: (when this method is used, neither session nor transcation can be closed or submitted; otherwise, ienumerrator cannot retrieve data)
String query = "select count (*) from member ";
Ienumerator E = session. createquery (query). enumerable (). getenumerator ();
E. movenext;
Int rowcount = (INT) (E. Current );

5. Return the specified (from 20 to 40) member
String query = "from member ";
Ilist members = session. createquery (query)
. Setfirstresult (20). setmaxresults (20). List ()

 

 

Nhiberante executes SQL statements

Using nhib.pdf. engine;

 

String SQL = "Update s_companyconfig set isvalid = {0} Where numconpanyid = {1} And nummodelid = {2 }";

SQL = string. Format (SQL, numvlaid, numcompanyid, nummodel );

Nhibernate. cfg. Configuration CFG = new Nhibernate. cfg. configuration ();

Isessionfactoryimplementor factory = (isessionfactoryimplementor) cfg. buildsessionfactory ();

System. Data. idbcommand cmd = new system. Data. sqlclient. sqlcommand ();

Cmd. commandtext = SQL;

System. Data. idbconnection conn = factory. openconnection ();

Cmd. Connection = conn;

Conn. open ();

Cmd. executenonquery ();

Conn. Close ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.