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

System.Linq.Queryable.TakeLast() could not be translated. #25242

Closed
ghost opened this issue Jul 12, 2021 · 2 comments
Closed

System.Linq.Queryable.TakeLast() could not be translated. #25242

ghost opened this issue Jul 12, 2021 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 12, 2021

Hello,

I have the following code:

Context.ApplicationVersions.OrderBy(x => x.ReleaseDate).TakeLast(versionsToRemoveCount).ToList();

The code throws an exception:

System.InvalidOperationException: 'The LINQ expression 'DbSet()
.OrderBy(x => x.ReleaseDate)
.TakeLast(__p_0)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'.

When I change the code to:

Context.ApplicationVersions.OrderByDescending(x => x.ReleaseDate).Take(versionsToRemoveCount).ToList();

everything works fine.

Data info:
ReleaseDate is type of DateTime, versionsToRemoveCount is type of Int32.

I am not sure if this behavior is correct or it is a bug.
Please take a look into it. Thank you!

EF Core version: 5.0.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.10.3

@ghost ghost added the customer-reported label Jul 12, 2021
@roji
Copy link
Member

roji commented Jul 12, 2021

Duplicate of #17065

@roji roji marked this as a duplicate of #17065 Jul 12, 2021
@roji
Copy link
Member

roji commented Jul 12, 2021

SkipLast and TakeLast aren't currently supported.

@roji roji closed this as completed Jul 12, 2021
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants