我们如何使用休眠条件API将列作为int排序? [英] How can we order a column as int using hibernate criteria API?

查看:69
本文介绍了我们如何使用休眠条件API将列作为int排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用休眠的Criteria API来获取数据表单数据库.

Hi I want to fetch the data form data base using hibernate Criteria API.

该数据应该在某些列中按数字排序.

That data should be ordered by some column as number.

此列在数据库中定义为varchar.但是我必须提取数字.

This column is defined as varchar in DB. But I have to fetch as numberic.

我使用标准API时遇到了问题,因为它只能像字符串一样订购.

I am facing problem using criteria API as it is ordering like string onyly.

例如: 我正在获取类似

Ex: I am getting data like

9、8、7、6、5、4、3、2、1,10

9, 8, 7, 6, 5, 4, 3, 2, 1,10

但我想要作为数据

10,9,8,7,6,5,4,3,2,1

10,9,8,7,6,5,4,3,2,1

是否有任何Hibernate方法将varchar转换为数字,例如convert("some column",int) 或cast("some column",int)吗?

Is there any Hibernate methods to covert varchar to number like convert("some column",int ) or cast("some column",int) ?

推荐答案

您可以使用Projections.Cast()进行cast(column as type).

.AddOrder(Projections.Cast(NHibernateUtil.Int32, Projections.Property("stringColumn"))

这篇关于我们如何使用休眠条件API将列作为int排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆