2010-05-20 51 views
2

您好我想使用hibernate Criteria API獲取數據表單數據庫。我們如何使用hibernate標準API將列定爲int?

該數據應按某個列的數量排序。

此列在數據庫中定義爲varchar。但我必須取數字。

我面臨使用標準API的問題,因爲它是像字符串一樣排序。

例: 我收到數據等

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

,但我想數據作爲

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

是否有任何Hibernate方法將varchar轉換爲數字,如convert(「some column」,int) 或cast(「some column」, int)?

回答

6

您可以使用Projections.Cast()做一個cast(column as type)

.AddOrder(Projections.Cast(NHibernateUtil.Int32, Projections.Property("stringColumn")) 
相關問題