Accepted answer

This for instance works and it sorts and returns an IList<T>:

public class Customer
    public int CustomerId { get; set; }
    public string Name { get; set; }
    public string City { get; set; }

public IList<Customer> GetSortedListOfCustomersInCity(string city)
    return context.Customers
        .Where(c => c.City == city)
        .OrderBy(c => c.Name)

(I think this is also what Reed Copsey in his answer meant.) I guess, your problem is of another kind, since it is too obvious that this example works. But I couldn't derive from your questions where exactly your issue is. A piece of your not working code is appreciated.


So my question is what do I from here? All I want to do is return data to the client (in this case the services), in an ordered fashion without changing return types all the way through my application.

When you create your queries, you can always return results.ToList(), which will evaluate them and convert them into an IList<T> for you.

This is, in many cases, advantageous if your query is an IQueryable<T> internally in any case, as it will fully evaluate the query, and prevent issues that can arise if you close your internal data context, then try to enumerate your results.

Related Articles