您的位置:首页 > 其它

【NHibernate】HQL入门

2015-07-12 15:36 253 查看
在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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: