I want to display results that don't have a secondary ID displayed first and then display items that do have a secondary ID. But then I need to Skip
and Take
.
IQueryable<thing> result;
IQueryable<thing> result2;
result2 = result
.Where(t => !(t.second_id == null || t.second_id.Trim() == string.Empty))
.OrderBy(t => t.second_id);
result = result
.Where(t => (t.second_id== null || t.second_id.Trim() == string.Empty))
.OrderBy(t => t.first_id);
result = result.Concat(result2);
return result
.Select(t => t.primary_key)
.Skip(pageSize * pageNumber)
.Take(pageSize)
.ToList();
The problem is that after Concat
the IQueryable
is no longer technically ordered so Skip
and Take
throw an error. Like this:
PagedList error: The method 'OrderBy' must be called before the method 'Skip'