码迷,mamicode.com
首页 > Web开发 > 详细

【NHibernate】HQL入门

时间:2015-07-12 17:12:20      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

 

在NHibernate 中 HQL 可以帮我们转成最终依赖数据库的查询脚本;

语法也甚是强大,适配主流数据库, HQL不支持union,要想取多个表数据可以做两次单独查询。

 

 

 IQuery query =
                NHibernateHelper.OpenSession()
                    .CreateQuery(
                        @"select p from Product as p,Product as pp where p.Name=pp.Name");
                       
            IList result = query.List();
            IEnumerator enu = result.GetEnumerator();
            while (enu.MoveNext())
            {
                object[] obj = (object[])enu.Current;     
            }

 

HQL

select p from Product as p,Product as pp where p.Name=pp.Name

MSSQL

NHibernate: select product0_.Id as Id0_, product0_.Name as Name0_, product0_.Category as Category0_, product0_.Discontinued as Disconti4_0_ from Product product0_, Product product1_ where product0_.Name=product1_.Name

 

【NHibernate】HQL入门

标签:

原文地址:http://www.cnblogs.com/viewcozy/p/4641021.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!