Question

I have a Nhibernate criteria on which I want to use sorting orderby asc.Below is my Nhibernate Criteria.

 IList<EmployeeDetails> results;
 results = BmDaoSession.CreateSQLQuery("exec Proc_ABC @Param1=" + batchNo + ", @Param2 ='" + flag + "', @Param3 ='" + backOfficeCompanyCode + "', @Param4 ='" + recordOption + "'")
    .SetResultTransformer(NHibernate.Transform.Transformers.AliasToBean(typeof(EmployeeDetails))).List<EmployeeDetails>();
return results;

Please suggest.

Was it helpful?

Solution

you can use linq to sort it, its OrderBy will do the job for you, by default it does ascending:

using System.Linq;

IList<Foo> list = new List<Foo>();
IEnumerable<Foo> sortedEnum = list.OrderBy(f=>f.Bar);
IList<Foo> sortedList = sortedEnum.ToList();

for Descending:

IEnumerable<Foo> sortedEnum = list.OrderByDescending(f=>f.Bar);
IList<Foo> sortedList = sortedEnum.ToList();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top