开发者

How can we order a column as int using hibernate criteria API?

Hi I want to fetch the data form data base开发者_JAVA技巧 using hibernate Criteria API.

That data should be ordered by some column as number.

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

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

but i want data as

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

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


You can use Projections.Cast() to do a cast(column as type).

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜