Answered by:
Order IList<Class> in Ascending Order

Question
-
User-436309264 posted
Hello Everyone,
I want to sort IList<ApplicationImage> by ApplicationName in Ascending order. How do I do it?
Here is the class.
public class ApplicationImage { public int ApplicationId { get; set;} public string ApplicationType { get; set; } public string ApplicationName { get; set; } public int ApplicationTypeId { get; set; } public string Wizard { get; set; } }
and the method:public IList<ApplicationImage> GetApplicationList() { using (var db = new ApplicationEntities()) { var query = from a in db.Applications where a.ApplictionTypeId > 1 select new ApplicationImage { ApplicationId = a.ApplicationId, ApplicationName = a.Name, Wizard = a.Wizard }; return query.ToList(); } }
I need the sort the query.ToList() in Ascending order by ApplicationName
Thanks
Kapil
Thursday, April 21, 2016 7:47 PM
Answers
-
User-286291038 posted
Hi Kapils573,
Please try,
var query = from a in db.Applications where a.ApplictionTypeId > 1 orderby a.Delivery.ApplicationName descending select new ApplicationImage { ApplicationId = a.ApplicationId, ApplicationName = a.Name, Wizard = a.Wizard }; return query.ToList();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 21, 2016 8:07 PM -
User1559292362 posted
Hi Kapils573,
As Nataraj Gandhi Arunachalam said, you could use orderby method in your LINQ statement. as your requirement, you need a ascending Order, try modify it like below:
var query = from a in db.Applications where a.ApplictionTypeId > 1 orderby a.Delivery.ApplicationName ascending select new ApplicationImage { ApplicationId = a.ApplicationId, ApplicationName = a.Name, Wizard = a.Wizard };
In addition, you could also use below code to achieve it.
var query = db.Applications.Where(a => a.ApplictionTypeId > 1).OrderBy(o => o.ApplicationName).Select(s=> new { ApplicationId = s.ApplicationId, ApplicationName =s.ApplicationName, Wizard = a.Wizard });
Best regards,
Cole Wu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 22, 2016 5:57 AM
All replies
-
User-286291038 posted
Hi Kapils573,
Please try,
var query = from a in db.Applications where a.ApplictionTypeId > 1 orderby a.Delivery.ApplicationName descending select new ApplicationImage { ApplicationId = a.ApplicationId, ApplicationName = a.Name, Wizard = a.Wizard }; return query.ToList();
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 21, 2016 8:07 PM -
User1559292362 posted
Hi Kapils573,
As Nataraj Gandhi Arunachalam said, you could use orderby method in your LINQ statement. as your requirement, you need a ascending Order, try modify it like below:
var query = from a in db.Applications where a.ApplictionTypeId > 1 orderby a.Delivery.ApplicationName ascending select new ApplicationImage { ApplicationId = a.ApplicationId, ApplicationName = a.Name, Wizard = a.Wizard };
In addition, you could also use below code to achieve it.
var query = db.Applications.Where(a => a.ApplictionTypeId > 1).OrderBy(o => o.ApplicationName).Select(s=> new { ApplicationId = s.ApplicationId, ApplicationName =s.ApplicationName, Wizard = a.Wizard });
Best regards,
Cole Wu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, April 22, 2016 5:57 AM