The property “Orders” is not loaded ! how can I change this code to Load the property “Orders” then get its count so I can use it sort?
IOrderedQueryable<Event> orderedQuery = (paging.SortDirection == SortDirection.Ascending)
? searchQuery.ToList().AsQueryable<Event>().OrderBy(e => e.Orders.Count)
: searchQuery.ToList()
.AsQueryable<Event>()
.OrderByDescending(e => e.Orders.Count);
ToList()executes the query and the resulting list won’t contain the Orders.It should work if you don’t call
ToList()in the first place: