Is it possible to define the sort order of a Child collection that is returned by a Parent object?
1 Answer, 1 is accepted
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.