NHIBERNATE query between multiple tables (objects)

xiaoxiao2021-03-06  17

In NHibernate, the HQL language is used, which is different from the traditional SQL query with the traditional SQL query. This, from its grammar, http://www.hibernate.org/documentation/hqlbnf. A relatively simple query code is as follows: ilist userlist = session.find ("from testmssql.student as student where student.name =?", "Zhang 3", NHIBERNATE.NHIBERNATE.STRING); the above code, represents from TestMssql. Students named "Zhang San" are found in the Student object table. If the connection query between multi-objects is involved, the code is as follows: ilist userlist = session.find ("from student s left outure join s.teacher as tom"); Query the teacher's name "Tom" s student. At the time of the test, I bind the result of the return to the DataGrid. The result is normal, but I have a problem with the following way: ilist userlist = session.find ("Select S.Name, T.TeacherName from Student s Left Outer Join S.TEacher As T.TEachername = 'EE' "); When binding to the DataGrid, displaying the properties of each object in ILIST, such as Rank, IsReadOnly, not required in the script Name, Teachername, what is this? Two ILISTs were carefully compared. When you use SELECT, it returns a Student object, otherwise it returns an object array (Object []), so there is a problem when binding to DataGrid. There is such a syntax in the HQL language: New classname Open SELECTEDPROPERTIESLIST CLOSE: You can build the queryed properties into a new class, such as: Select New StudentInfo (S.Name, T.TEachername) from student s left outer Join S.TEacher As T.TeacherName = 'EE', but I found new classes in the process of trying again, that is to say that StudentInfo and its hbm.xml file must be implemented. This will lose meaning. NHIBERNATE's document is too small, can only be a model, now I have to start watching Hibernate documents.

转载请注明原文地址:https://www.9cbs.com/read-44766.html

New Post(0)