开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜