码迷,mamicode.com
首页 > 其他好文 > 详细

Hql 子查询

时间:2015-04-15 18:51:08      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

直接上代码:

 public virtual IList<VoucherLog> GetMaxResultVoucherLog()
        {
            string orgaizationCode = HttpContext.Current.Session["OrganizationCode"].ToString();
            return this.Session.CreateQuery("select h from VoucherLog h where h.PeopleCode in (SELECT A.Code from  User A where A.organization.Id = :orgaizationCode) Order by h.Code desc")
             .SetString("orgaizationCode", orgaizationCode)
             .SetMaxResults(1)
             .List<VoucherLog>();
        }

在代码中我用in实现过滤子查询。在写hql语句的时候我们要特别注意,hql语句中出现的属性必须和对象中的属性对应上,如果是对象的话,要使用对象的关系如:

A.organization.Id  这就说明在User这个对象中还有一个带关系的organization对象,所有赋值的时候,应严格按照关系来走。

Hql 子查询

标签:

原文地址:http://www.cnblogs.com/gaolizhong/p/4429050.html

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