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 queries with Concat on two entities and Count #9004

Closed
maumar opened this issue Jun 28, 2017 · 2 comments
Closed
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Jun 28, 2017

query:

context.Gears.Concat(context.Gears).Count();

exception:

Expression of type 'System.Collections.Generic.IEnumerable`1[Microsoft.EntityFrameworkCore.Storage.ValueBuffer]' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[System.Object]' of method 'System.Collections.Generic.IEnumerable`1[System.Object] Concat[Object](System.Collections.Generic.IEnumerable`1[System.Object], 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.Call(MethodInfo method, Expression arg0, Expression arg1)
	C:\git\EntityFramework\src\EFCore\Query\ResultOperatorHandler.cs(531,0): at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleSetOperation(EntityQueryModelVisitor entityQueryModelVisitor, Expression secondSource, MethodInfo setMethodInfo)
	C:\git\EntityFramework\src\EFCore\Query\ResultOperatorHandler.cs(144,0): at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleConcat(EntityQueryModelVisitor entityQueryModelVisitor, ConcatResultOperator concatResultOperator)
	C:\git\EntityFramework\src\EFCore\Query\ResultOperatorHandler.cs(36,0): at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.<>c.<.cctor>b__33_4(EntityQueryModelVisitor v, ResultOperatorBase r, QueryModel __)
	C:\git\EntityFramework\src\EFCore\Query\ResultOperatorHandler.cs(89,0): at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore.Relational\Query\Internal\RelationalResultOperatorHandler.cs(68,0): at Microsoft.EntityFrameworkCore.Query.Internal.RelationalResultOperatorHandler.HandlerContext.EvalOnClient(Boolean requiresClientResultOperator)
	C:\git\EntityFramework\src\EFCore.Relational\Query\Internal\RelationalResultOperatorHandler.cs(156,0): at Microsoft.EntityFrameworkCore.Query.Internal.RelationalResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore\Query\EntityQueryModelVisitor.cs(1139,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index)
	C:\git\EntityFramework\src\EFCore.Relational\Query\RelationalQueryModelVisitor.cs(1133,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index)
	at Remotion.Linq.QueryModelVisitorBase.VisitResultOperators(ObservableCollection`1 resultOperators, QueryModel queryModel)
	at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore\Query\EntityQueryModelVisitor.cs(694,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore.Relational\Query\RelationalQueryModelVisitor.cs(266,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore\Query\EntityQueryModelVisitor.cs(176,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore\Storage\Database.cs(70,0): at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore\Query\Internal\QueryCompiler.cs(139,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, INodeTypeProvider nodeTypeProvider, IDatabase database, IDiagnosticsLogger`1 logger, Type contextType)
	C:\git\EntityFramework\src\EFCore\Query\Internal\QueryCompiler.cs(103,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_0`1.<Execute>b__0()
	C:\git\EntityFramework\src\EFCore\Query\Internal\CompiledQueryCache.cs(69,0): at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
	C:\git\EntityFramework\src\EFCore\Query\Internal\CompiledQueryCache.cs(44,0): at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
	C:\git\EntityFramework\src\EFCore\Query\Internal\QueryCompiler.cs(99,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
	C:\git\EntityFramework\src\EFCore\Query\Internal\EntityQueryProvider.cs(62,0): at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
	at System.Linq.Queryable.Count[TSource](IQueryable`1 source)

This happens because requies materialization detects that result converges to single value, and therefore query sources don't need to be materialized - however our current implementation of Concat/Union/Except/Intersect needs those query sources to be materialized, because the translation is on the client.

We should add compensation logic to cover this until we can properly translate those result operators to sql

@smitpatel
Copy link
Member

Can you post QueryModel for either of the issue?

maumar added a commit that referenced this issue Jul 1, 2017
#8524 - Query: data corruption for queries with set result operators (Concat/Union etc) and collection navigations
#8525 - Query: compilation error for queries with navigations inside set result operators and Count
#9004 - Query: compilation error for queries with Concat on two entities and Count

Problem was that for set result operators we always need to materialize both sets, even if they are wrapped around scalar result operator (e.g. Count). This is needed because set result operators are currently performed on the client.

Also, we need to inject MaterializeCollectionNavigation calls into set result operators, so that the IQuerySource that is the argument to the set operator is wrapped in its own query source.

Also fixed some minor bugs in the MaterializeCollectionNavigation injector, which surfaced once the visitor started going inside SubQueryExpressions (it wasn't necessary before because we only needed to materialize top level collection).
@ajcvickers ajcvickers added this to the 2.0.0 milestone Jul 3, 2017
maumar added a commit that referenced this issue Jul 3, 2017
#8524 - Query: data corruption for queries with set result operators (Concat/Union etc) and collection navigations
#8525 - Query: compilation error for queries with navigations inside set result operators and Count
#9004 - Query: compilation error for queries with Concat on two entities and Count

Problem was that for set result operators we always need to materialize both sets, even if they are wrapped around scalar result operator (e.g. Count). This is needed because set result operators are currently performed on the client.

Also, we need to inject MaterializeCollectionNavigation calls into set result operators, so that the IQuerySource that is the argument to the set operator is wrapped in its own query source.

Also fixed some minor bugs in the MaterializeCollectionNavigation injector, which surfaced once the visitor started going inside SubQueryExpressions (it wasn't necessary before because we only needed to materialize top level collection).
maumar added a commit that referenced this issue Jul 5, 2017
#8524 - Query: data corruption for queries with set result operators (Concat/Union etc) and collection navigations
#8525 - Query: compilation error for queries with navigations inside set result operators and Count
#9004 - Query: compilation error for queries with Concat on two entities and Count

Problem was that for set result operators we always need to materialize both sets, even if they are wrapped around scalar result operator (e.g. Count). This is needed because set result operators are currently performed on the client.

Also, we need to inject MaterializeCollectionNavigation calls into set result operators, so that the IQuerySource that is the argument to the set operator is wrapped in its own query source.

Also fixed some minor bugs in the MaterializeCollectionNavigation injector, which surfaced once the visitor started going inside SubQueryExpressions (it wasn't necessary before because we only needed to materialize top level collection).
@maumar
Copy link
Contributor Author

maumar commented Jul 5, 2017

fixed in e1d7b16

@maumar maumar closed this as completed Jul 5, 2017
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants