Efcore: InvalidOperationException: Processing of the LINQ expression after upgrade to .Net Core 3.1 (from 2.2)

Created on 7 Jan 2020  路  5Comments  路  Source: dotnet/efcore

_From @ferronsw on Tuesday, January 7, 2020 2:14:03 PM_

I'm running Visual Studio 2019 on Windows 10 1809.
After I've upgraded my app from .Net Core 2.2 to 3.1 I'm getting an Linq error with this code:

var userGroupGuids = ClaimsPrincipalExtension.GetUserGroupGuids(principal);
var avaiablePortal = customerPortals.Select(x => x.Group).Intersect(userGroupGuids).ToList();

This worked just fine before the migration. When I change the second line to this is works:

var avaiablePortal = customerPortals.ToList().Select(x => x.Group).Intersect(userGroupGuids).ToList();

Is this because of a change or a bug?

Trace:

InvalidOperationException: Processing of the LINQ expression 'DbSet<Portal> .Where(x => x.CustomerId == __customer_Id_0) .Select(x => x.Group) .Intersect(__p_1)' 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.


Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
    System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
    Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.Expand(Expression query)
    Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
    Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor<TResult>(Expression query)
    Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery<TResult>(Expression query, bool async)
    Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore<TResult>(IDatabase database, Expression query, IModel model, bool async)
    Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler+<>c__DisplayClass9_0<TResult>.<Execute>b__0()
    Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore<TFunc>(object cacheKey, Func<Func<QueryContext, TFunc>> compiler)
    Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery<TResult>(object cacheKey, Func<Func<QueryContext, TResult>> compiler)
    Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute<TResult>(Expression query)
    Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute<TResult>(Expression expression)
    Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable<TResult>.GetEnumerator()
    System.Collections.Generic.List<T>..ctor(IEnumerable<T> collection)
    System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
    Switch.OLW.Client.Helpers.Portal.LayoutBuilder.Build(ClaimsPrincipal principal) in LayoutBuilder.cs

                    var avaiablePortal = customerPortals.Select(x => x.Group).Intersect(userGroupGuids).ToList();

Switch.OLW.Client.Controllers.HomeController.Index() in HomeController.cs

                Portal portal = _layoutBuilder.Build(User);

lambda_method(Closure , object , object[] )
Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(object target, object[] parameters)
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

_Copied from original issue: dotnet/core#4087_

area-query customer-reported type-enhancement

Most helpful comment

We probably don't have any thing in the backlog. In order to process this on server side, we need to send whole list to server side in some form. With that list of unmapped scalars is out of question. There are various different themes for the rest.

  • Join with client side scalar list is basic filter which can be written using Where in more readable way.
  • Concat with client side list has no usability as either way you are going to get all data back from server.
  • Union would be similar to above except for duplicates. Even in this case the original data is coming back from server.
  • Intersect/Except both can be written using Where.

All 5 comments

By design. We don't translate Intersect with client side List to server. Exception message improved to throw client evaluation error in 5.0

@smitpatel Close as by-design?

Can we get the why this is by design and how to achieve an intersection between a user set and a server? This is a perfectly legitimate operation and just saying by design is not very community friendly.

@smitpatel Is "Intersect with client side List" something we have on the backlog?

We probably don't have any thing in the backlog. In order to process this on server side, we need to send whole list to server side in some form. With that list of unmapped scalars is out of question. There are various different themes for the rest.

  • Join with client side scalar list is basic filter which can be written using Where in more readable way.
  • Concat with client side list has no usability as either way you are going to get all data back from server.
  • Union would be similar to above except for duplicates. Even in this case the original data is coming back from server.
  • Intersect/Except both can be written using Where.
Was this page helpful?
0 / 5 - 0 ratings