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 navigations inside set result operators and Count #8525

Closed
maumar opened this issue May 19, 2017 · 2 comments
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 May 19, 2017

query:

context.Gears.Select(g => g.Weapons.Concat(g.Weapons).Count())

throws:

System.ArgumentException : 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(1034,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index)
	C:\git\EntityFramework\src\EFCore.Relational\Query\RelationalQueryModelVisitor.cs(1136,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(589,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore.Relational\Query\RelationalQueryModelVisitor.cs(269,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore.Relational\Query\RelationalQueryModelVisitor.cs(446,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitSubQueryModel(QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore.Relational\Query\ExpressionVisitors\SqlTranslatingExpressionVisitor.cs(888,0): at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.VisitSubQuery(SubQueryExpression expression)
	at Remotion.Linq.Clauses.Expressions.SubQueryExpression.Accept(ExpressionVisitor visitor)
	at Remotion.Linq.Parsing.ThrowingExpressionVisitor.Visit(Expression expression)
	C:\git\EntityFramework\src\EFCore.Relational\Query\ExpressionVisitors\SqlTranslatingExpressionVisitor.cs(110,0): at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.Visit(Expression expression)
	C:\git\EntityFramework\src\EFCore.Relational\Query\ExpressionVisitors\RelationalProjectionExpressionVisitor.cs(195,0): at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalProjectionExpressionVisitor.Visit(Expression expression)
	C:\git\EntityFramework\src\EFCore\Query\EntityQueryModelVisitor.cs(923,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore.Relational\Query\RelationalQueryModelVisitor.cs(1054,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
	at Remotion.Linq.Clauses.SelectClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel)
	at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore\Query\EntityQueryModelVisitor.cs(589,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore.Relational\Query\RelationalQueryModelVisitor.cs(269,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
	C:\git\EntityFramework\src\EFCore\Query\EntityQueryModelVisitor.cs(170,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)
	--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
	C:\git\EntityFramework\src\EFCore\Query\Internal\QueryCompiler.cs(159,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(102,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(98,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 Remotion.Linq.QueryableBase`1.GetEnumerator()
@maumar
Copy link
Contributor Author

maumar commented May 19, 2017

those query sources are not marked for materialization (because of Count), but it seems that Concat result operator require them to be materialized

@ajcvickers ajcvickers added this to the 2.0.0 milestone May 22, 2017
@maumar maumar changed the title Query: compilation error for queries with set result operators and Count Query: compilation error for queries with navigations inside set result operators and Count Jun 29, 2017
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).
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

2 participants