开发者

Help with Nhibernate query?

开发者 https://www.devze.com 2023-02-18 07:02 出处:网络
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 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

精彩评论

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

关注公众号