Nhibernate使用HQL返回自定义类型
2010-08-25 21:32
435 查看
摘要:使用HQL返回自定义类型的结果集。
前提:已经定义好Customer类及其Nhibernate映射文件xml。
输出SQL
说明
CustomerFirstnameCounter中的Count属性必须定义为long类型,如果定义为int类型,则会报如下错误:
前提:已经定义好Customer类及其Nhibernate映射文件xml。
表结构及数据
自定义类
Mapping文件
条件查询(Criteria Query)
public IList<CustomerFirstnameCounter> GetCustomerFirstnameCounts() { ISession session = GetSession(); return session.CreateQuery(@"select new CustomerFirstnameCounter(c.Firstname,count(c.Firstname)) from Customer c group by c.Firstname") .List<CustomerFirstnameCounter>(); }
输出SQL
NHibernate: select customer0_.Firstname as col_0_0_, count(customer0_.Firstname) as col_1_0_ from Customer customer0_ group by customer0_.Firstname
说明
CustomerFirstnameCounter中的Count属性必须定义为long类型,如果定义为int类型,则会报如下错误:
Test method DataAccessLayer.Test.NhibernateDataProviderTest.GetCustomerFirstnameCountsTest threw exception: NHibernate.QueryException: Unable to locate appropriate constructor on class [DataTransfer.CustomerFirstnameCounter, DataTransfer] [select new CustomerFirstnameCounter(c.Firstname,count(c.Firstname)) from DataTransfer.Customer c group by c.Firstname] ---> NHibernate.InstantiationException: no constructor compatible with (System.String, System.Int64) found in class: DataTransfer.CustomerFirstnameCounter
相关文章推荐
- 使用自定义JavaScriptConverter返回自定义的复杂类型
- 使用Hibernate返回自定义类型时报错的问题
- 使用Hibernate返回自定义类型时报错的问题
- 使用VS2012 MFC自定义消息时,处理函数不能返回void类型。
- 在HQL select查询语句中自定义查询结果返回的数据类型
- hql查询返回list,map,自定义类型
- webwok中使用自定义的返回类型(result_type)
- java中的方法返回值使用泛型,实现灵活的返回值类型
- 关于Column '*' not found 解决方案 Hibernate使用SQL查询返回实体类型,即返回某个类,或实体类
- PowerDesign 使用 用户自定义字段类型 domain 后 生成物理模型图 生成的sql脚本 类型 替换问题
- Oracle type (自定义类型的使用)
- 在主函数中提示用户输入用户名和密码。另写一方法来判断用户输入是否正确。该方法分别返回一个bool类型的登录结果和和一个string类型的登录信息。如登录成功,返回true及“登录成功”,若登录失败则返回false及“用户名错误”或“密码错误”(使用out参数)
- Android Toolbar使用系统原生返回键,并改变其颜色,自定义图片替换系统原生返回键
- 怎样在hibernate的HQL语句中使用mysql 的自定义函数?
- 如何在Qt中使用自定义数据类型
- JSON的使用、利用正则表达式解决不定类型返回Json格式
- jeecms 中使用@cms_channel 标签和@cms_content标签返回的list类型的channel和content所对应的属性名
- 使用泛型解决需要动态返回类型的问题
- SkinMagic使用后按钮加自定义图标或菜单GetMneu返回NULL的解决方法
- 使用自定义类型做qmap,qhash的key