question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$skip is not applied when $orderby is not defined

See original GitHub issue

I’ve encountered issue when using standalone $skip parameter, for example corebuilding?$skip=2

I think problem lies in GetQueryableMethod method:

if (orderByClause == null)
{
    return Expression.Call
    (
        expression.Type.IsIQueryable() ? typeof(Queryable) : typeof(Enumerable),
        "Take",
        new[] { type },
        expression,
        Expression.Constant(top.Value)
    );;
}

So, if OrderByClause is not defined, only Take expression is going to be returned, without applying Skip expression.

Before starting with the fix, could you tell me if this is actually a bug, or intended behavior. To me, it looks like the bug.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
wbuckcommented, Feb 16, 2022

Yeah, so currently I’m generating a default order for the following cases:

  1. orderby is null but skip is not null
  2. orderby is null but top is not null
  3. orderby is null but both top and skip are not null

I agree with you about using the same method for generating an order, keep things consistent. I’ll start on creating such a method and go from there.

1reaction
BlaiseDcommented, Feb 16, 2022

That’s a good point point regarding Top. Do we not want to apply the same rules? Maybe we should.

With regard to generating an OrdeyBy, the algorithm itself does not matter - better to use the same one in both cases.

Two ways to go:

  1. Select the first public property which is a literal type.
  2. Select all properties which are keys (If my memory is correct ASP.NET OData requires each entity to have an Id property or have the [Key] attribute applied).

Here’s an example of some code getting the first literal type.

I like the 2nd option better. You’d be calling MemberInfo.GetCustomAttributes() to see if System.ComponentModel.DataAnnotations.KeyAttribute has been applied (if there is no Id property).

So if GenerateStableOrder is not available for both cases I would just create a new method which does the same thing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How to solve "The method 'Skip' is only supported for ...
The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'."...
Read more >
Can't use take and skip alongside order by in querybuilder ...
I noticed that in all the queries I try to do that involve any type of join , the orderBy statement can't be...
Read more >
False positive "Skip/Take without OrderBy" when using ...
When using .UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery) we get a the following warning The query uses a row limiting ...
Read more >
ORDER BY Clause (Transact-SQL) - SQL Server
The ORDER BY clause does not guarantee ordered results when these constructs are queried, unless ORDER BY is also specified in the query...
Read more >
SQL Order by Clause overview and examples
It does not skip the next value in rank if we have multiple rows with similar values. The NTILE function divides the complete...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found