tags:

views:

77

answers:

1

Hi I want to fetch the data form data base 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) ?

+1  A: 

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

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