首页 / 软件开发 / .NET编程技术 / Castle ActiveRecord学习实践(7) 使用HQL查询
Castle ActiveRecord学习实践(7) 使用HQL查询2011-02-03 cnblogs terrylee主要内容1.HQL概述2.SimpleQuery查询3.ScalarQuery查询4.自定义查询5.使用CallBack一.HQL简单介绍HQL全名是Hibernate Query Language,它是一种完全面向对象的查询语言。先来看一下HQL最基本的一些用法1.From子句from Post你也可以为Post起一个别名from Post as post或者省略asfrom Post post2.Select 子句select Name,Author from Blog也可以使用elements函数来查询一个集合select elements(blog.Posts) from Blog blog3.使用聚合函数HQL中也可以使用一些聚合函数select count(*) from Blog blogselect count(elements(blog.Posts)) from Blog blogHQL支持的聚合函数有avg(), sum(), min(), max()count(*)count(), count(distinct ), count(all)4.Where子句from Blog blog where blog.Name = ‘Terry Lee’from Blog blog where blog.Name is not null详细可以参考http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html。