IOrderedQueryable

Feb 25, 2015 at 4:01 PM
When you examine the query, it is always IOrderedQueryable even though no ordering has be applied..

Can you confirm if this is correct :
var items = _repository.Query(query)
                .OrderBy(x => ApplySorting2(x, sortTerms))
                .SelectPage(page, pageSize, out totalCount);
private IOrderedQueryable<Item> ApplySorting2(IQueryable<Item> query, string sortTerms)
        {
            if (sortTerms.IsNullOrWhiteSpace()) return null;

            var terms = sortTerms.Split(',');

            foreach (var term in terms)
                ApplyTerm(query, term);

            return (IOrderedQueryable<Item>) query;
        }
private void ApplyTerm(IQueryable<Item> query, string term)
        {
            if (query is IOrderedQueryable<Item>)
            {
                // thenby
               // ALWAYS ORDERED
            }
            else
            {
                // orderby
            }
        }
Marked as answer by lelong37 on 5/12/2015 at 10:01 AM