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

SkipWhile: Processing of the LINQ expression failed #18962

Closed
Neme12 opened this issue Nov 17, 2019 · 6 comments · Fixed by #22648
Closed

SkipWhile: Processing of the LINQ expression failed #18962

Neme12 opened this issue Nov 17, 2019 · 6 comments · Fixed by #22648
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@Neme12
Copy link

Neme12 commented Nov 17, 2019

Steps to reproduce

using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;

namespace ConsoleApp3
{
    public sealed class Record
    {
        public int Id { get; set; }
        public DateTime Time { get; set; }
    }

    public sealed class ApplicationDbContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=aspnet-WebApplication-6E483A89-BEE6-4A76-96CC-CEB276E5E112;Trusted_Connection=True;MultipleActiveResultSets=true");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
        }

        public DbSet<Record> Records { get; set; }
    }

    public static class Program
    {
        public static void Main()
        {
            using (var context = new ApplicationDbContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                context.Records.Add(new Record { Time = new DateTime(2019, 11, 16) });
                context.Records.Add(new Record { Time = new DateTime(2019, 11, 17) });
                context.Records.Add(new Record { Time = new DateTime(2019, 11, 18) });
                context.SaveChanges();
            }

            using (var context = new ApplicationDbContext())
            {
                var record = context.Records.Find(2);

                var previousRecord = context.Records
                    .OrderByDescending(r => r.Time)
                    .ThenByDescending(r => r.Id)
                    .SkipWhile(r => r.Id != record.Id)
                    .Skip(1)
                    .FirstOrDefault();
            }
        }
    }
}

After running this, I get this exception:

System.InvalidOperationException: 'Processing of the LINQ expression 'SkipWhile(
source: ThenByDescending<Record, int>(
source: OrderByDescending<Record, DateTime>(
source: DbSet,
keySelector: (r) => r.Time),
keySelector: (r) => r.Id),
predicate: (r) => r.Id != (Unhandled parameter: __record_Id_0))' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.'

I assume this is because SkipWhile isn't actually implemented (looking at #14104), but the error message is really cryptic. It's an InvalidOperationException simply saying that processing the expression failed and mentions that it might be a bug in EF Core.

Running the same code under EF Core 2.2, I get:

System.NotSupportedException: 'Could not parse expression 'value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[ConsoleApp3.Record]).OrderByDescending(r => r.Time).ThenByDescending(r => r.Id).SkipWhile(r => (r.Id != __record_Id_0))': This overload of the method 'System.Linq.Queryable.SkipWhile' is currently not supported.'

which is much clearer - it tells me that SkipWhile isn't supported. This is at the very least a regression in the readability of this error message.

Further technical details

EF Core version: 3.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0
Operating system: Windows 10 Version 1903
IDE: Visual Studio 16.4.0 Preview 5.0

@ajcvickers
Copy link
Contributor

Putting this on the backlog to throw a better exception.

@ajcvickers ajcvickers added this to the Backlog milestone Nov 18, 2019
@smitpatel smitpatel added the verify-fixed This issue is likely fixed in new query pipeline. label Mar 16, 2020
@smitpatel
Copy link
Contributor

Probably the exception is already improved.

@AndriySvyryd AndriySvyryd modified the milestones: Backlog, MQ Sep 2, 2020
@maumar
Copy link
Contributor

maumar commented Sep 21, 2020

current exception:

The LINQ expression 'DbSet<Customer>()
        .OrderBy(c => c.CustomerID)
        .SkipWhile(c => c.CustomerID != "Foo")' 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'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
  Stack Trace: 

@maumar maumar closed this as completed Sep 21, 2020
@maumar maumar reopened this Sep 21, 2020
maumar added a commit that referenced this issue Sep 21, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
maumar added a commit that referenced this issue Sep 21, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
maumar added a commit that referenced this issue Sep 21, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
@maumar maumar added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed verify-fixed This issue is likely fixed in new query pipeline. labels Sep 21, 2020
maumar added a commit that referenced this issue Sep 21, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
maumar added a commit that referenced this issue Sep 22, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
maumar added a commit that referenced this issue Sep 22, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
maumar added a commit that referenced this issue Sep 22, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
maumar added a commit that referenced this issue Sep 22, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
maumar added a commit that referenced this issue Sep 22, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
maumar added a commit that referenced this issue Sep 22, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
@ghost ghost closed this as completed in #22648 Sep 22, 2020
ghost pushed a commit that referenced this issue Sep 22, 2020
Resolves #12274
Resolves #11835
Resolves #12597
Resolves #12379
Resolves #12717
Resolves #17775
Resolves #18962
@Neme12
Copy link
Author

Neme12 commented Sep 24, 2020

@maumar But that exception message still doesn't tell me why it couldn't be translated. It's basically the same as the original exception message with the query inside it. But I feel the the exception should say that SkipWhile isn't supported. This might be a trivial example but when I get this exception in a long query, I'm completely lost as to what could be wrong and which part or which combination of features EF Core doesn't support.

@Neme12
Copy link
Author

Neme12 commented Sep 24, 2020

The exception message in EF Core 2.2 is still much better because it tells me that it's the SkipWhile method that isn't supported/implemented.

@smitpatel
Copy link
Contributor

When query translation fails, if there is anything specific we indicate the reason (like using not mapped property). Otherwise it is the last query operator in exception message which fails the whole query. We will consider improving it in future if there is enough user feedback that it is not clear.

@ajcvickers ajcvickers modified the milestones: MQ, 6.0.0 Nov 25, 2020
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-preview1 Jan 27, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview1, 6.0.0 Nov 8, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants