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 query with Except projecting a constant #12568

Closed
maumar opened this issue Jul 5, 2018 · 4 comments · Fixed by #18576
Closed

Query: compilation error for query with Except projecting a constant #12568

maumar opened this issue Jul 5, 2018 · 4 comments · Fixed by #18576
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 Jul 5, 2018

query:

ctx.Customers.Except(ctx.Customers).Select(e => 1)

exception:

Expression of type 'System.Collections.Generic.IEnumerable`1[System.Int32]' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[System.Object]' of method 'System.Collections.Generic.IEnumerable`1[System.Object] Except[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)
	at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleSetOperation(EntityQueryModelVisitor entityQueryModelVisitor, Expression secondSource, MethodInfo setMethodInfo)
	at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleExcept(EntityQueryModelVisitor entityQueryModelVisitor, ExceptResultOperator exceptResultOperator)
	at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.<>c.<.cctor>b__33_9(EntityQueryModelVisitor v, ResultOperatorBase r, QueryModel __)
	at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.Internal.RelationalResultOperatorHandler.HandlerContext.EvalOnClient(Boolean requiresClientResultOperator)
	at Microsoft.EntityFrameworkCore.Query.Internal.RelationalResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index)
	at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index)
	at Remotion.Linq.Clauses.ResultOperatorBase.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
	at Remotion.Linq.QueryModelVisitorBase.VisitResultOperators(ObservableCollection`1 resultOperators, 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.CreateQueryExecutor[TResult](QueryModel queryModel)
	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()
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database, IDiagnosticsLogger`1 logger, Type contextType)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass13_0`1.<Execute>b__0()
	at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
	at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
	at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
	at Remotion.Linq.QueryableBase`1.GetEnumerator()
	at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
	at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
	at Microsoft.EntityFrameworkCore.Query.SimpleQueryTestBase`1.Except_simple(Boolean isAsync)
	at Microsoft.EntityFrameworkCore.Query.SimpleQuerySqlServerTest.Except_simple(Boolean isAsync)
@roji
Copy link
Member

roji commented Jun 26, 2019

This issue disappears with the new implementation of set operations (PR #16249).

roji added a commit to roji/efcore that referenced this issue Jun 26, 2019
Also found some more skipped set operation tests, unskipped and
rearranged them.

Fixes dotnet#12568
roji added a commit that referenced this issue Jun 26, 2019
Also found some more skipped set operation tests, unskipped and
rearranged them.

Fixes #12568
roji added a commit to roji/efcore that referenced this issue Jun 26, 2019
Also found some more skipped set operation tests, unskipped and
rearranged them.

Fixes dotnet#12568
roji added a commit to roji/efcore that referenced this issue Jun 27, 2019
Also found some more skipped set operation tests, unskipped and
rearranged them.

Fixes dotnet#12568
roji added a commit that referenced this issue Jun 27, 2019
Also found some more skipped set operation tests, unskipped and
rearranged them.

Fixes #12568
roji added a commit to roji/efcore that referenced this issue Jun 27, 2019
Also found some more skipped set operation tests, unskipped and
rearranged them.

Fixes dotnet#12568
roji added a commit that referenced this issue Jun 27, 2019
Also found some more skipped set operation tests, unskipped and
rearranged them.

Fixes #12568
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 27, 2019
roji added a commit that referenced this issue Jun 28, 2019
Also found some more skipped set operation tests, unskipped and
rearranged them.

Fixes #12568
@roji roji removed the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 2, 2019
@roji
Copy link
Member

roji commented Jul 2, 2019

The original issue disappears but the test now fails with:

System.InvalidCastException : Unable to cast object of type 'System.String' to type 'System.Int32'.
   at Microsoft.Data.SqlClient.SqlBuffer.get_Int32()
   at Microsoft.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
   at Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalShapedQueryCompilingExpressionVisitor.QueryingEnumerable`1.Enumerator.MoveNext() in /home/roji/projects/EFCore/src/EFCore.Relational/Query/Pipeline/QueryingEnumerable.cs:line 143
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.SimpleQueryTestBase`1.Union_Select_constant() in /home/roji/projects/EFCore/test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.SetOperations.cs:line 225
   at Microsoft.EntityFrameworkCore.Query.SimpleQuerySqlServerTest.Union_Select_constant() in /home/roji/projects/EFCore/test/EFCore.SqlServer.FunctionalTests/Query/SimpleQuerySqlServerTest.SetOperations.cs:line 211

@smitpatel
Copy link
Contributor

Check the shaper expression before compiling into QueryingEnumerable. Possible cause of error is unexpected column getting projected and mangling index.

@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jul 24, 2019
@roji roji modified the milestones: Backlog, 3.1.0 Aug 23, 2019
@roji
Copy link
Member

roji commented Oct 24, 2019

Verified and this no longer fails.

@roji roji modified the milestones: Backlog, 3.0.0 Oct 24, 2019
@roji roji added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed punted-for-3.0 punted-for-3.1 labels Oct 24, 2019
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

Successfully merging a pull request may close this issue.

5 participants