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: Bring back support for UseRowNumberForPaging #16400

Closed
smitpatel opened this issue Jul 2, 2019 · 53 comments
Closed

Query: Bring back support for UseRowNumberForPaging #16400

smitpatel opened this issue Jul 2, 2019 · 53 comments
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. type-enhancement

Comments

@smitpatel
Copy link
Member

No description provided.

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 2, 2019

In 7 days: https://blogs.msdn.microsoft.com/sqlreleaseservices/end-of-mainstream-support-for-sql-server-2008-and-sql-server-2008-r2/

@ajcvickers ajcvickers added this to the Backlog milestone Jul 5, 2019
@ajcvickers
Copy link
Member

Notes from triage:

  • Putting this on the backlog for now; we may implement it post 3.0 if there is enough demand. However, need for this may be correlated code that only runs on .NET Framework, which would make it pointless for 3.0 or beyond.
  • We will announce this as a breaking change and call it out in the blog post; keeping this in 3.0 until those two things are done.

@ajcvickers ajcvickers modified the milestones: Backlog, 3.0.0 Jul 5, 2019
@ajcvickers ajcvickers changed the title Query: RowNumberPaging support Query: Bring back support for UseRowNumberForPaging Jul 10, 2019
ajcvickers added a commit to dotnet/EntityFramework.Docs that referenced this issue Jul 11, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jul 11, 2019
ajcvickers added a commit to dotnet/EntityFramework.Docs that referenced this issue Jul 11, 2019
@John0King
Copy link

🤣 microsoft is merciless to microsoft's own product

@fengshi19888
Copy link

if don't suppport the "row_num" for paging ,any other way to solve it besides upgrade database.
many company are still use "sqlserver 2008r2".

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 16, 2019

Please add a vote for the first post here if you really need this

@effun
Copy link

effun commented Sep 28, 2019

Upgrading database may cost lots of money. Just for paging function? My boss would say NO to me. Then I should have these options.

  1. Stay with core 2.2 and cry.
  2. Use express edition for higher version of SQL Server. I'm not sure that can be used in commercial.
  3. Move to other database product and cry louder.
  4. Do nothing.

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 28, 2019

Express can be used commercially, but has some resource constraints

@John0King
Copy link

I think this is what cause the .net community is smaller than other language, even .net is better, the support policy (not just support , in fact it just can not use ) of keep dropping user/devs , make company that use .net less than less those year in China .

and for the rownumber paging feature, juse use SELECT [<UserColumns>] FROM ( SELECT [<UserColumns>], RowNumber() Over (Order by [orderby column]) as ____EF_Row_Column FROM (<orginal sql>) WHERE ____EF_Row_Column between <start> and <end> ) as ___EF_internal )
that will be the same like the new paging function , just there is two more ()

and with this pattern , EF can add a new feature .AsSubQuery() , this is a feature I want for a long ago when there some complex query doesn't work. EF should tread it like a Table/View after .AsSubQuery() , and it will make user can do more complex query in a more “manually” way .

@ghost
Copy link

ghost commented Sep 30, 2019

Very user unfriendly to remove this feature if specially promised keep it in ef 3.0.
Now it was a surprise, after my application refactory to EF 3, that it is not working.

@ghost
Copy link

ghost commented Oct 8, 2019

i don't think it's related to support of SQL Server 2008. Row number paging is supported in transact sql - now and in the future. New Sql Server releases support it too, but the Net.Core EF 3.0 dropped this support in favor of the newer construct. We don't ask you to support Sql Server 2008, but to allow to use the older paging method.

@smitpatel
Copy link
Member Author

We don't ask you to support Sql Server 2008, but to allow to use the older paging method.

If newer construct is available in all SqlServer versions we support and it consistent across different types of database, then what value it provides to write additional code to use older paging method? Do you have any data points how it is significantly more beneficial to use older paging method on let's say SqlServer 2016?

@ghost
Copy link

ghost commented Oct 8, 2019

We don't ask you to support Sql Server 2008, but to allow to use the older paging method.

If newer construct is available in all SqlServer versions we support and it consistent across different types of database, then what value it provides to write additional code to use older paging method? Do you have any data points how it is significantly more beneficial to use older paging method on let's say SqlServer 2016?

Yes, it's beneficial, but not on a standalone SqlServer 2016, but if you have, say 10 instances of sql server - 3 Sql Server 2008, 6 Sql Server 2012 and 1 Sql Server 2016, then you would use one common technology to access that data. In terms of query performances it would be the same.

@SureshYadagiri
Copy link

Lot of projects still using SQL Server 2008. It's nice to have pagination support.

@ghost
Copy link

ghost commented Jan 29, 2020

Lot of projects still using SQL Server 2008. It's nice to have pagination support.

By the way, if you did not noticed - the issue is closed. Try to find other solutions, and there are many

@gate21
Copy link

gate21 commented Mar 12, 2020

In the comment by yyjdelete on 1/11/2020
optionsBuilder.ReplaceService<IQueryTranslationPostprocessorFactory, SqlServer2008QueryTranslationPostprocessorFactory>();
Where do I locate SqlServer2008QueryTranslationPostprocessorFactory?

@yyjdelete
Copy link

@gate21
#16400 (comment)
Click details in my above comment with modern browsers.
image

@Codename2200
Copy link

Codename2200 commented Apr 1, 2020

I still get this error for 3.1.2
'SqlServerDbContextOptionsBuilder.UseRowNumberForPaging(bool)' is obsolete: 'Row-number paging is no longer supported. See https://aka.ms/AA6h122 fore more information'.

When I run the project it gives me this error:

Core Microsoft SqlClient Data Provider | Incorrect syntax near 'OFFSET'.\r\nInvalid usage of the option NEXT in the FETCH statement.

Is there any workaround to this?

@Dunge
Copy link

Dunge commented May 13, 2020

Which LINQ query is impacted by this? Is it only Skip()?

I plan to move ahead with EF3.1 on a SQL2008 server (upgrading later), I only have two queries using skip and can be rewritten differently. Anything else I should be looking for?

Take() will still works right? (it converts to TOP in SQL)

@dlmotter
Copy link

dlmotter commented Aug 3, 2020

Azure Synapse Analytics Server (Azure Data Warehouse) databases also do not support OFFSET, so it would be really nice to bring back RowNumberPaging for that. Unlike SQL2008, ASAS is not deprecated and needs support for this as well.

@David-Moreira
Copy link

Hello guys. I also just came up with this problem in .NET 5, unfortunately still using SQL Server 2008.
I was trying to use @yyjdelete 's solution, but I can't seem to find the SqlServerQueryTranslationPostprocessor anywhere in Microsoft.EntityFrameworkCore.SqlServer.Query.Internal
Any ideas?

@yyjdelete
Copy link

@David-Moreira
Not tested, maybe you should use Microsoft.EntityFrameworkCore.Query.RelationalQueryTranslationPostprocessor instead

@David-Moreira
Copy link

@yyjdelete thank you for the quick answer, I'll take a look when possible and let you know if it worked.

@lawhorkl
Copy link

lawhorkl commented Feb 2, 2021

as with every time I run into an issue like this with .NET its sad to see the .NET dev team's unhalting attitude toward backward compatibility.

Its admirable to want to appear to always push for change and the latest tech however in reality I think it usually turns more into "Allowing backward compatibility is hard, so we arent going to do it." while putting out the folks that can't upgrade for very reasonable and not unusual reasons.

Sorry Microsoft, this is not how you do open source and this is why the .NET ecosystem shrinks every day. 0/10.

@gate21
Copy link

gate21 commented Feb 2, 2021

I am not sure what the fuss is about, all of us have told our clients / consumers of our API's that we can no longer support a feature.

EF Core team gave us a workaround "SqlServer2008QueryTranslationPostprocessorFactory", I have been using it with EF 3.x in Production for some time now, and it works fine.

Thanks guys for giving us a workaround.

@David-Moreira
Copy link

@yyjdelete
Once again thank you for your time. Just now I was testing this.
The Microsoft.EntityFrameworkCore.Query.RelationalQueryTranslationPostprocessor works as substitute.
What should be in this line, on SqlExpressionFactory? I injected a ISqlExpressionFactory
query = new Offset2RowNumberConvertVisitor(query, SqlExpressionFactory).Visit(query);

I then tried running and I get this:

System.InvalidOperationException: Calling 'ShapedQueryExpression.VisitChildren' is not allowed. Visit the expression manually for the relevant part in the visitor.
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression.VisitChildren(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)
   at Template.Api.Infrastructure.SqlServer2008QueryTranslationPostprocessorFactory.SqlServer2008QueryTranslationPostprocessor.Offset2RowNumberConvertVisitor.VisitExtension(Expression node)

@shaunpenfold
Copy link

@yyjdelete
Once again thank you for your time. Just now I was testing this.
The Microsoft.EntityFrameworkCore.Query.RelationalQueryTranslationPostprocessor works as substitute.
What should be in this line, on SqlExpressionFactory? I injected a ISqlExpressionFactory
query = new Offset2RowNumberConvertVisitor(query, SqlExpressionFactory).Visit(query);

I then tried running and I get this:

System.InvalidOperationException: Calling 'ShapedQueryExpression.VisitChildren' is not allowed. Visit the expression manually for the relevant part in the visitor.
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryExpression.VisitChildren(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)
   at Template.Api.Infrastructure.SqlServer2008QueryTranslationPostprocessorFactory.SqlServer2008QueryTranslationPostprocessor.Offset2RowNumberConvertVisitor.VisitExtension(Expression node)

Stuck at the same issue, tried many different Interfaces, cant seem to figure it out.

@smitpatel
Copy link
Member Author

smitpatel commented Mar 10, 2021

In the Offset2RowNumberConvertVisitor class modify VisitExtension method as following

		protected override Expression VisitExtension(Expression node)
                {
			if (node is ShapedQueryExpression shapedQueryExpression)
           	 	{
                		return shapedQueryExpression.Update(Visit(shapedQueryExpression.QueryExpression), shapedQueryExpression.ShaperExpression);
            		}
                        if (node is SelectExpression se)
                            node = VisitSelect(se);
                        return base.VisitExtension(node);
                }

Then it will work as before.

@Rwing
Copy link

Rwing commented Apr 8, 2021

Hi guys,
I created a library to bring back the UseRowNubmerForPaging method based @yyjdelete 's code.
https://www.nuget.org/packages/EntityFrameworkCore.UseRowNumberForPaging/
thank you!

@jitendrajadav
Copy link

Hi guys,
I created a library to bring back the UseRowNubmerForPaging method based @yyjdelete 's code.
https://www.nuget.org/packages/EntityFrameworkCore.UseRowNumberForPaging/
thank you!

This is really help me a lot it save my day I was struggling and find this is really really awesome!

Thank you very much

@David-Moreira
Copy link

That's great!
When I had this problem, I did find that there's two already existing nuget packages which do something similar, like this one:
https://www.nuget.org/packages/EfCore.SqlServer2008Query/

However I don't know if yours or that one does something more. Thanks @Rwing

@Rwing
Copy link

Rwing commented Apr 12, 2021

@David-Moreira Sorry I didn't see this library before.
I think they have the same core code, and maybe my library's api is more friendly :)

@David-Moreira
Copy link

Yea, and a nice friendly MIT license on it!
Thanks! :)

@ssg
Copy link

ssg commented Oct 6, 2021

The NuGet packages target only EF Core 5.0. In order to use it on EF Core 3.1, use the hack code by @yyjdelete in this thread.

@sfsharapov
Copy link

sfsharapov commented Nov 16, 2021

Are there any workaround for EF Core 6.0?

@yltsa
Copy link

yltsa commented Dec 9, 2021

Are there any workaround for EF Core 6.0?

I use EF Core 6.0 and the UseRowNumberForPaging nuget package. It comes the following error:

An unhandled exception occurred while processing the request.
InvalidOperationException: SelectExpression.GenerateOuterColumn() is not found
EntityFrameworkCore.UseRowNumberForPaging.SqlServer2008QueryTranslationPostprocessorFactory+SqlServer2008QueryTranslationPostprocessor+Offset2RowNumberConvertVisitor..cctor()

TypeInitializationException: The type initializer for 'Offset2RowNumberConvertVisitor' threw an exception.
EntityFrameworkCore.UseRowNumberForPaging.SqlServer2008QueryTranslationPostprocessorFactory+SqlServer2008QueryTranslationPostprocessor+Offset2RowNumberConvertVisitor..ctor(Expression root, ISqlExpressionFactory sqlExpressionFactory)

@ssg
Copy link

ssg commented Dec 9, 2021

Someone needs to adapt the workaround code to EF Core 6.0. It's not portable between versions as it relies on internal implementation details. That's why you're getting the error.

I wish EF Core team had never dropped the legacy support. I think maintaining it in EF Core codebase would be way easier than maintaining third-party workarounds.

@floydhamandi
Copy link

Any news where we stand on this?

@yltsa
Copy link

yltsa commented Jan 4, 2022

Hi, I wrote before about the error. Now have noticed, that the sw works OK at home office, where is the newest SQL server. But at work the paging is not OK with an old Microsoft SQL server.

@benyaminl
Copy link

Hi, I wrote before about the error. Now have noticed, that the sw works OK at home office, where is the newest SQL server. But at work the paging is not OK with an old Microsoft SQL server.

The package of https://www.nuget.org/packages/EntityFrameworkCore.UseRowNumberForPaging/ works with SQL2008R2

Tested with https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks2008r2/adventure-works-2008r2-oltp.bak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. type-enhancement
Projects
None yet
Development

No branches or pull requests