Skip to content

Query: Skip with Count always returns 0 #7523

Closed

Description

@archanasoni

We are working to have Core support for IBM EntityFramework Provider.
For one of our internal test application, we have to skip few rows and and return remaining total number of rows.
Our query is:
context.ArchTable1.OrderBy(c=>c.Id).Skip(1).Count()

It always returns output:
skip count 0
We have used UseRowNumberForPaging() via optionsBuilder.

The similar Application when we run against SQL Server 2008, we do see same issue.
Generated SQL is:
SELECT [t].[c0]
FROM (
SELECT COUNT(*) AS [c0], ROW_NUMBER() OVER(ORDER BY @@rowcount) AS [RowNumber]
FROM [ArchTable1] AS [a]
) AS [t]
WHERE [t].[RowNumber] > 1

With manual modification in above query, if we run from SQL management Studio it returns the desired output:
SELECT COUNT(*) AS [c0] from
(select ROW_NUMBER() OVER(ORDER BY @@rowcount) AS [RowNumber]
FROM [ArchTable1] AS [a]
) AS [t]
WHERE [t].[RowNumber] > 1

Now questions are:

  1. Though user mentioned OrdeyBy clause, but why it's not reflecting in generated query ?
  2. PushDownSubquery() basically pushes down the current query. How do we inject some new SQL (i.e. select statement to achieve above working query) in between in current selectExpression ?

Activity

  1. self-assigned this
    on Feb 1, 2017
  2. added this to the 2.0.0 milestone on Feb 1, 2017
  3. changed the title [-]Skip with Count always returns 0[/-] [+]Query: Skip with Count always returns 0[/+] on May 9, 2017
  4. ajcvickers commented on Nov 14, 2018

    @ajcvickers
    Contributor

    @archanasoni If you are still using RowNumberForPaging, could you please comment on issue #13959 and let us know why?

  5. modified the milestones: , 2.0.0 on Oct 15, 2022
  6. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions