Help with Nhibernate query?
Please can anyone help me in changing the below T-SQL query to NHibernate query:
Select * From **TableName** Order By Convert(int,**VarcharColumnNameContainsOnlyNumbers**) Desc
Please note that when I used the below query I got wrong ordered data:
mySession.CreateCriteria<**EntityName**>()
.AddOrder(new Order("**VarcharColumnNameContainsOnlyNumbers**", false))
.List<**EntityName**&开发者_如何学Gogt;();
Thank you in advance.
You can use Projections in your Order
.AddOrder(Order.Desc(Projections.Cast(NHibernateUtil.Int32,
Projections.Property("VarCharColumnName")))
I used the below code and it's solved :)
mySession.CreateSQLQuery("Select * From **TableName** Order By Convert(int,**VarcharColumnNameContainsOnlyNumbers**) Desc").SetMaxResults(1).UniqueResult<string>();
Thanks All.
精彩评论