在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