Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Include with OrderBy with Skip(0) cause OrderBy to be ignored #6736

Closed
303248153 opened this issue Oct 9, 2016 · 0 comments
Closed
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@303248153
Copy link

Use Include with OrderBy with Skip(0) will cause OrderBy gets ignored.

Steps to reproduce

This is the standalone project for reproduce the problem
EFExample.zip

The main code is as follows

using (var context = new ExampleContext())
{
    var authors = context.Set<Author>();
    Console.WriteLine("order by age");
    var result = authors
        .Include(a => a.Articles)
        .OrderBy(a => a.Age).Skip(0).Take(100).ToList();
    foreach (var author in result)
    {
        Console.WriteLine(author.Name);
    }
    Console.WriteLine();

    Console.WriteLine("order by age descending");
    result = authors
        .Include(a => a.Articles)
        .OrderByDescending(a => a.Age).Skip(0).Take(100).ToList();
    foreach (var author in result)
    {
        Console.WriteLine(author.Name);
    }
    Console.ReadLine();
}

The output is

order by age
Steve
John

order by age descending
Steve
John

The issue

EF generated following SQL

exec sp_executesql N'SELECT [t].[Id], [t].[Age], [t].[CreateTime], [t].[Deleted], [t].[Name], [t].[UpdateTime]
FROM (
    SELECT [a].[Id], [a].[Age], [a].[CreateTime], [a].[Deleted], [a].[Name], [a].[UpdateTime], ROW_NUMBER() OVER(ORDER BY [a].[Age]) AS [__RowNumber__]
    FROM [Author] AS [a]
) AS [t]
WHERE ([t].[__RowNumber__] > @__p_0) AND ([t].[__RowNumber__] <= (@__p_0 + @__p_1))
ORDER BY [t].[Id]',N'@__p_0 int,@__p_1 int',@__p_0=0,@__p_1=100
go

Further technical details

EF Core version: 1.0.1
Operating system: Windows 8.1
Visual Studio version: VS2015 update 3

@rowanmiller rowanmiller added this to the 1.2.0 milestone Oct 10, 2016
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 31, 2016
smitpatel added a commit that referenced this issue Apr 6, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 6, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 6, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Introduce ISqlServerOptions, SqlServerOptions to flow SqlServerDbOptionsExtension to SqlServerQuerySqlGenerator as singleton service to get value of RowNumberPaging
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Introduce ISqlServerOptions, SqlServerOptions to flow SqlServerDbOptionsExtension to SqlServerQuerySqlGenerator as singleton service to get value of RowNumberPaging
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Introduce ISqlServerOptions, SqlServerOptions to flow SqlServerDbOptionsExtension to SqlServerQuerySqlGenerator as singleton service to get value of RowNumberPaging
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Introduce ISqlServerOptions, SqlServerOptions to flow SqlServerDbOptionsExtension to SqlServerQuerySqlGenerator as singleton service to get value of RowNumberPaging
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Introduce ISqlServerOptions, SqlServerOptions to flow SqlServerDbOptionsExtension to SqlServerQuerySqlGenerator as singleton service to get value of RowNumberPaging
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Introduce ISqlServerOptions, SqlServerOptions to flow SqlServerDbOptionsExtension to SqlServerQuerySqlGenerator as singleton service to get value of RowNumberPaging
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 7, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Introduce ISqlServerOptions, SqlServerOptions to flow SqlServerDbOptionsExtension to SqlServerQuerySqlGenerator as singleton service to get value of RowNumberPaging
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
smitpatel added a commit that referenced this issue Apr 10, 2017
- We dont need to copy always now since new IncludeCompiler lifts order by at query model level
- Move RowNumberPagingExpressionVisitor to SqlServerQuerySqlGenerator
- Introduce ISqlServerOptions, SqlServerOptions to flow SqlServerDbOptionsExtension to SqlServerQuerySqlGenerator as singleton service to get value of RowNumberPaging
- Remove SqlServerQueryModelVisitor
- Add explicit tests for #6736
@ajcvickers ajcvickers changed the title Include with OrderBy with Skip(0) cause OrderBy gets ignored Query: Include with OrderBy with Skip(0) cause OrderBy to be ignored May 9, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 10, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants