Skip to content

Query: Translate ToList.EnumerableMethod() #19466

New issue

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

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

Already on GitHub? # to your account

Closed
groege opened this issue Jan 3, 2020 · 2 comments
Closed

Query: Translate ToList.EnumerableMethod() #19466

groege opened this issue Jan 3, 2020 · 2 comments

Comments

@groege
Copy link

groege commented Jan 3, 2020

Given following query

_context.TransportOrder.Select(x => new TransportOrder() {
    TransportOrderData = new TransportOrderData() 
    {
        ExternalTransportOrderNumber = x.TransportOrderData.ExternalTransportOrderNumber, 
        StatusId = x.TransportOrderData.StatusId
    }, 
    TransportOrderSharedData = new TransportOrderSharedData() 
    {
        TransportOrderNumber = x.TransportOrderSharedData.TransportOrderNumber
    }, 
    Supplier = new TransportAddress() 
    {
        AddressName = x.Supplier.AddressName
    }, 
    Carrier = new TransportAddress() 
    {
        TechEmail = x.Carrier.TechEmail
    }, 
    Driver = new TransportAddress() {
        TechEmail = x.Driver.TechEmail
    }, 
    PickUpAddress = new TransportAddress()
    {
        AddressName = x.PickUpAddress.AddressName, 
        ZipCode = x.PickUpAddress.ZipCode, 
        City = x.PickUpAddress.City, 
        Street = x.PickUpAddress.Street
    }, 
    DeliveryAddress = new TransportAddress() {
        AddressName = x.DeliveryAddress.AddressName, 
        ZipCode = x.DeliveryAddress.ZipCode, 
        City = x.DeliveryAddress.City, 
        Street = x.DeliveryAddress.Street
    }, 
    SubCarrier = new TransportAddress() 
    {
        TechEmail = x.SubCarrier.TechEmail
    }, 
    LogisticsContactPersons = x.LogisticsContactPersons.Select(y => new TransportAddress() 
    {
         AddressName = y.Address.AddressName
    }).ToList(), 
    Projects = x.Projects.Select(y => new TransportProject() {
        ProjectNumber = y.Data.ProjectNumber, 
        Species = y.Data.Species, Assortment = y.Data.Assortment
}).ToList()})
//it doesn't matter whats inside any ==> y.ProjectNumber == null is broken as well
.Where(x => x.Projects.Any(y => EF.Functions.ILike(y.ProjectNumber, "%a%")))
.ToList();

Returns the following exception:

System.InvalidOperationException
HResult=0x80131509
Message=The LINQ expression 'DbSet
.Where(o => DbSet
.Where(o0 => EF.Property<Nullable>(o, "TransportOrderGuid") != null && EF.Property<Nullable>(o, "TransportOrderGuid") == EF.Property<Nullable>(o0, "TransportOrderGuid"))
.Select(o0 => new TransportProject{
ProjectNumber = EF.Property(o0, "Data").ProjectNumber,
Species = EF.Property(o0, "Data").Species,
Assortment = EF.Property(o0, "Data").Assortment
}
)
.ToList()
.Any(y => __Functions_0
.ILike(
_: y.ProjectNumber,
matchExpression: "%a%")))' 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 either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.g__CheckTranslated|8_0(ShapedQueryExpression translated, <>c__DisplayClass8_0& )
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_01.<ExecuteAsync>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.CountAsync[TSource](IQueryable1 source, CancellationToken cancellationToken)
at FreightExchange.Extensions.GraphQlExtensions.d__18`2.MoveNext() in C:\Users\haberl\source\repos\carriermobile\FreightExchange\Extensions\GraphQlExtensions.cs:line 401

Further technical details

EF Core version: 3.1
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: NET Core 3.1
Operating system: WIN 10
IDE: Visual Studio 2019 16.4.0 Preview 6.0

@groege groege added the type-bug label Jan 3, 2020
@ajcvickers
Copy link
Contributor

@smitpatel to find dupe.

@smitpatel smitpatel changed the title Where statement containing any with predicate or where cannot be translated Query: Translate ToList.EnumerableMethod() Jan 3, 2020
@smitpatel smitpatel self-assigned this Jan 3, 2020
@smitpatel smitpatel added this to the 5.0.0 milestone Jan 3, 2020
@smitpatel
Copy link
Contributor

Fixed in #19377

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants