It sounds like you should might want to make Paginate
still take an IOrderedQueryable<T>
to validate at compile-time that you've started with something that's ordered - but you don't then need to assign back to the same variable. For example:
protected List<T> Paginate(IOrderedQueryable<T> content, int? skip, int? take)
{
// Different variable type so that we can assign to it below...
IQueryable<T> result = content;
if (skip.HasValue) result = result.Skip(skip.Value);
if (skip.HasValue && take.HasValue) result = result.Take(take.Value);
return result.ToList();
}
And as Marc notes, it would probably be better to change the Take
line to:
if (take.HasValue) result = result.Take(take.Value);