This is a migrated thread and some comments may be shown as answers.

Sorting Child Collections

1 Answer 51 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tim
Top achievements
Rank 1
Tim asked on 19 Mar 2013, 05:35 PM
Is it possible to define the sort order of a Child collection that is returned by a Parent object?

1 Answer, 1 is accepted

Sort by
0
Yordan
Telerik team
answered on 21 Mar 2013, 01:04 PM
Hello Tim,

It is possible. Sorting of child collection is done in exactly the same manner like sorting an ordinary collection. For example consider the Northwind database. We have a category and we want to sort the child products of that category based on some conditions. This can be done in the following way:
  
using (NorthwindContext context = new NorthwindContext())
{
var productsByNameAsc = context.Categories.First().Products.OrderBy(p => p.ProductName);
var productsByNameDesc = context.Categories.First().Products.OrderByDescending(p => p.ProductName);
var productsBySuppCityAsc = context.Categories.First().Products.OrderBy(p => p.Supplier.City);
var productsBySuppCityDesc = context.Categories.First().Products.OrderByDescending(p => p.Supplier.City);
}

I hope that helps. If this is not your case for sorting child collections please get back to us for assistance.

Regards,
Yordan
the Telerik team
Free Webinar: OpenAccess Integration in Sitefinity. SIGN UP NOW.
Tags
General Discussions
Asked by
Tim
Top achievements
Rank 1
Answers by
Yordan
Telerik team
Share this question
or