NHibernate--HQL

Source: Internet
Author: User

Use the HQL in NHibernate to query the data.

Code:

1         /// <summary> 2         /// Find Events 3         /// </summary> 4         Private void Btn_select_click (object  sender, EventArgs e)5        { 6 7         }

1. Query, and use parameters:

1             //* * * Query * * *2IQuery query = session. CreateQuery ("From person p where p.id =? and P.name =: Name");3 4             //using parameters in NHibernate5             //one is "?" and one uses ":". If you use? , then the direct representation of the location, if used:, then use: The following file name6             //statements in NHibernate:7             //Nhibernate:select person0_. Id as id0_, person0_. Name as name0_ from person person0_ where [email protected] and [email protected]; @p0 = 2, @p1 = ' event aaaaaaaa '8             //at this point 0 represents the first parameter9             //at this point 1 represents the second parameterTenQuery. Setparameter (0,2);//use?  OneQuery. Setparameter ("name","Test");//use: A  -ilist<person> list = query. List<person>(); -  the              This. label3. Text = list[0]. Id.tostring () + list[0]. Name.tostring ();

2. Query-Specify the number of queries, such as from 2nd-5th data:

1             //* * * Query specified number of rows * * *2IQuery query = session. CreateQuery (" from person");3 4ilist<person> list = query. List<person>();5 6             //assign a value to the list again7             //Query the data between the 3--5 bar, using the subscript index, 0 for the first article. 8List = list. Skip<person> (3). Take<person> (5). Tolist<person>();9 Ten              This. label3. Text = list[2]. Id.tostring () +" "+ list[2]. Name.tostring ();

Put 1 or 2 in the top code.

NHibernate--HQL

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.