- 爱易网页
 
                        - 
                            C#教程
 
                        - 在C#里使用NHibernate,怎么使用连接查询 
 
                         
                    
                    
                    日期:2014-05-18  浏览次数:20971 次 
                    
                        
                         在C#里使用NHibernate,如何使用连接查询?
测试两个表: 
 department.hbm.xml 
  
  <?xml   version= "1.0 "   encoding= "utf-8 "   ?>  
  <hibernate-mapping   xmlns= "urn:nhibernate-mapping-2.2 ">  
 	 <class   name= "Test.Model.Department,   Test.Model "   table= "department ">  
 		 <id   name= "Id "   type= "Int16 "   unsaved-value= "null ">  
 			 <column   name= "id "   length= "2 "   sql-type= "smallint "   not-null= "true "   unique= "true "   index= "PK_department "/>  
 			 <generator   class= "native "   />  
 		 </id>  
 		 <property   name= "Departmentname "   type= "String ">  
 			 <column   name= "departmentname "   length= "50 "   sql-type= "varchar "   not-null= "true "/>  
 		 </property>  
 		 <bag   name= "departmentemployees "   inverse= "true "   lazy= "true "   outer-join= "true "         cascade= "all-delete-orphan ">  
 			 <key   column= "department "/>  
 			 <one-to-many   class= "Test.Model.Employee,   Test.Model "/>  
 		 </bag>  
 	 </class>  
  </hibernate-mapping>  
  
 上表存有数据: 
 id            departmentname 
 1               技术 
  
 另一个表Employee.hbm.xml: 
  
  <?xml   version= "1.0 "   encoding= "utf-8 "   ?>  
  <hibernate-mapping   xmlns= "urn:nhibernate-mapping-2.2 ">  
 	 <class   name= "Test.Model.Employee,   Test.Model "   table= "employee ">  
 		 <id   name= "Id "   type= "Int32 "   unsaved-value= "null ">  
 			 <column   name= "id "   length= "4 "   sql-type= "int "   not-null= "true "   unique= "true "   index= "PK_employee "/>  
 			 <generator   class= "native "   />  
 		 </id>  
 		 <property   name= "Name "   type= "String ">  
 			 <column   name= "name "   length= "50 "   sql-type= "varchar "   not-null= "false "/>  
 		 </property>  
 		 <property   name= "Age "   type= "Int16 ">  
 			 <column   name= "age "   length= "2 "   sql-type= "smallint "   not-null= "false "/>  
 		 </property>  
 		 <many-to-one   name= "department "   class= "Test.Model.Department,   Test.Model "   outer-join= "true ">  
 			 <column   name= "department "   length= "2 "   sql-type= "smallint "   not-null= "true "/>  
 		 </many-to-one>  
 	 </class>  
  </hibernate-mapping>  
 数据为 
 Name      Age      department 
 张三      20         1 
  
 想要实现的功能就是在查询时能够列出完整的信息: 
 Name            Age            Department 
 张三            20                  技术 
  
 在文件里面怎么写?
------解决方案--------------------