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: compilation error for async queries with client evaluation that directly project collection navigation #12449

Closed
maumar opened this issue Jun 22, 2018 · 1 comment
Assignees
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. type-bug

Comments

@maumar
Copy link
Contributor

maumar commented Jun 22, 2018

Repro using GearsOfWarModel:

from g in ctx.Gears
where !g.HasSoulPatch && FavoriteWeapon(EF.Property<List<Weapon>>(g, "Weapons")).Name == "Cole's Gnasher"
select g.Nickname

Exception:

Expression of type 'System.Collections.Generic.IAsyncEnumerable`1[Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.Weapon]' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[System.Object]' of method 'System.Collections.Generic.ICollection`1[Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.Weapon] MaterializeCollectionNavigation[Weapon](Microsoft.EntityFrameworkCore.Metadata.INavigation, System.Collections.Generic.IEnumerable`1[System.Object])'
	at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
	at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ReadOnlyCollection`1& arguments)
	at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
	at System.Linq.Expressions.MethodCallExpressionN.Rewrite(Expression instance, IList`1 args)
	at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node)
	at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
	at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMethodCall(MethodCallExpression node)
	at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitMember(MemberExpression node)
	at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
	at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
	at Remotion.Linq.Clauses.WhereClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
	at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
	at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Storage.Database.CompileAsyncQuery[TResult](QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass22_0`1.<CompileAsyncQuery>b__0()
	at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
	at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddAsyncQuery[TResult](Object cacheKey, Func`1 compiler)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQuery[TResult](Expression query)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query)
	at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression)
	at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.System.Collections.Generic.IAsyncEnumerable<TResult>.GetEnumerator()
@maumar maumar changed the title Query: compilation error for async queries with client evaluation Query: compilation error for async queries with client evaluation that directly project collection navigation Jun 22, 2018
@ajcvickers ajcvickers added this to the 3.0.0 milestone Jun 27, 2018
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Aug 3, 2018
@ajcvickers
Copy link
Contributor

Closing as no longer relevant due to query changes.

@ajcvickers ajcvickers removed this from the 3.0.0 milestone May 11, 2019
smitpatel added a commit that referenced this issue Aug 10, 2019
SelectMany in linq look something like following (second clause is considered the collection selector)
```C#
from c in cs
from o in c.Orders
select....
```
Following are the translations of SelectMany

Unrelated collection selector
```C#
from c in cs
from o in os
```
Generates CROSS JOIN

Correlated collection selector with correlation being a predicate
```C#
from c in cs
from o in os.Where(o => o.CustomerID == c.CustomerID)
```
Such predicate can be lifted and used in generating a join. So this query generates JOIN.
If collection selector ends with DefaultIfEmpty then it is LEFT JOIN.

Correlated collection selector with correlation not a predicate
```C#
from c in cs
from o in os.Select(o => c.City)
```
Since we cannot generate a join predicate here, this translates to CROSS APPLY.
If collection selector ends with DefaultIfEmpty then it is OUTER APPLY.

Add support for Cross Apply
Add Support for Outer Apply
Convert Cross Apply to Inner Join when possible
Convert Outer Apply to Left Join when possible
Add translation for DefaultIfEmpty
Add translation for both overloads of SelectMany
Handle DefaultIfEmpty & SelectMany without collectionSelector in Navigation Expansion
Ensure columns are in projection when generating join predicate from a correlated subquery

Currently there are no tests for Cross/Outer Apply.
Our earlier Cross Apply got converted to join. N+1 evaluation tests are disabled right now, which would generate Cross Apply.
We never supported Outer Apply in past.

Resolves #15711
Resolves #12567
Resolves #12572
Resolves #12872
Resolves #16330
Resolves #15081
Resolves #16989

Re-enable tests for #12449
smitpatel added a commit that referenced this issue Aug 10, 2019
SelectMany in linq look something like following (second clause is considered the collection selector)
```C#
from c in cs
from o in c.Orders
select....
```
Following are the translations of SelectMany

Unrelated collection selector
```C#
from c in cs
from o in os
```
Generates CROSS JOIN

Correlated collection selector with correlation being a predicate
```C#
from c in cs
from o in os.Where(o => o.CustomerID == c.CustomerID)
```
Such predicate can be lifted and used in generating a join. So this query generates JOIN.
If collection selector ends with DefaultIfEmpty then it is LEFT JOIN.

Correlated collection selector with correlation not a predicate
```C#
from c in cs
from o in os.Select(o => c.City)
```
Since we cannot generate a join predicate here, this translates to CROSS APPLY.
If collection selector ends with DefaultIfEmpty then it is OUTER APPLY.

- Add support for Cross Apply
- Add Support for Outer Apply
- Convert Cross Apply to Inner Join when possible
- Convert Outer Apply to Left Join when possible
- Add translation for DefaultIfEmpty
- Add translation for both overloads of SelectMany
- Handle DefaultIfEmpty & SelectMany without collectionSelector in Navigation Expansion
- Ensure columns are in projection when generating join predicate from a correlated subquery

Currently there are no tests for Cross/Outer Apply.
Our earlier Cross Apply got converted to join. N+1 evaluation tests are disabled right now, which would generate Cross Apply.
We never supported Outer Apply in past.

Resolves #15711
Resolves #12567
Resolves #12572
Resolves #12872
Resolves #16330
Resolves #15081
Resolves #16989

Re-enable tests for #12449
smitpatel added a commit that referenced this issue Aug 12, 2019
SelectMany in linq look something like following (second clause is considered the collection selector)
```C#
from c in cs
from o in c.Orders
select....
```
Following are the translations of SelectMany

Unrelated collection selector
```C#
from c in cs
from o in os
```
Generates CROSS JOIN

Correlated collection selector with correlation being a predicate
```C#
from c in cs
from o in os.Where(o => o.CustomerID == c.CustomerID)
```
Such predicate can be lifted and used in generating a join. So this query generates JOIN.
If collection selector ends with DefaultIfEmpty then it is LEFT JOIN.

Correlated collection selector with correlation not a predicate
```C#
from c in cs
from o in os.Select(o => c.City)
```
Since we cannot generate a join predicate here, this translates to CROSS APPLY.
If collection selector ends with DefaultIfEmpty then it is OUTER APPLY.

- Add support for Cross Apply
- Add Support for Outer Apply
- Convert Cross Apply to Inner Join when possible
- Convert Outer Apply to Left Join when possible
- Add translation for DefaultIfEmpty
- Add translation for both overloads of SelectMany
- Handle DefaultIfEmpty & SelectMany without collectionSelector in Navigation Expansion
- Ensure columns are in projection when generating join predicate from a correlated subquery

Currently there are no tests for Cross/Outer Apply.
Our earlier Cross Apply got converted to join. N+1 evaluation tests are disabled right now, which would generate Cross Apply.
We never supported Outer Apply in past.

Resolves #15711
Resolves #12567
Resolves #12572
Resolves #12872
Resolves #16330
Resolves #15081
Resolves #16989

Re-enable tests for #12449
smitpatel added a commit that referenced this issue Aug 13, 2019
SelectMany in linq look something like following (second clause is considered the collection selector)
```C#
from c in cs
from o in c.Orders
select....
```
Following are the translations of SelectMany

Unrelated collection selector
```C#
from c in cs
from o in os
```
Generates CROSS JOIN

Correlated collection selector with correlation being a predicate
```C#
from c in cs
from o in os.Where(o => o.CustomerID == c.CustomerID)
```
Such predicate can be lifted and used in generating a join. So this query generates JOIN.
If collection selector ends with DefaultIfEmpty then it is LEFT JOIN.

Correlated collection selector with correlation not a predicate
```C#
from c in cs
from o in os.Select(o => c.City)
```
Since we cannot generate a join predicate here, this translates to CROSS APPLY.
If collection selector ends with DefaultIfEmpty then it is OUTER APPLY.

- Add support for Cross Apply
- Add Support for Outer Apply
- Convert Cross Apply to Inner Join when possible
- Convert Outer Apply to Left Join when possible
- Add translation for DefaultIfEmpty
- Add translation for both overloads of SelectMany
- Handle DefaultIfEmpty & SelectMany without collectionSelector in Navigation Expansion
- Ensure columns are in projection when generating join predicate from a correlated subquery

Currently there are no tests for Cross/Outer Apply.
Our earlier Cross Apply got converted to join. N+1 evaluation tests are disabled right now, which would generate Cross Apply.
We never supported Outer Apply in past.

Resolves #15711
Resolves #12567
Resolves #12572
Resolves #12872
Resolves #16330
Resolves #15081
Resolves #16989

Re-enable tests for #12449
@ajcvickers ajcvickers added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Mar 10, 2022
@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
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. type-bug
Projects
None yet
Development

No branches or pull requests

2 participants