'Typecasting IQueryable<T> to IOrderedQueryable<T>

Does anyone know if there's any potential issues typecasting an IQueryable<T> to IOrderedQueryable<T>?

public IOrderedQueryable<T> ApplyFilter<T>(IOrderedQueryable<T> query)
{
    // NOTE: Skip() and Take() both return IQueryable<T>
    return (IOrderedQueryable<T>)query
        .Skip((CurrentPage - 1) * PageSize)
        .Take(PageSize);
}

Even though IOrderedQueryable<T> implements IQueryable<T> and not the other way around, IOrderedQueryable<T> has no members of its own. So it doesn't seem to matter and, in fact, appears to work.

But does it have the potential to cause problems? And, if so, is there another efficient way?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source