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