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 projecting optional navigation, paging and another projecting of optional navigation #6618

Closed
maumar opened this issue Sep 27, 2016 · 4 comments
Assignees
Labels
area-test 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 Sep 27, 2016

Repro using ComplexQueryModel:

                var query = context.LevelOne
                    .Select(l1 => l1.OneToOne_Optional_FK)
                    .OrderBy(l2 => l2.Id)
                    .Take(10)
                    .Select(l2 => l2.OneToOne_Optional_FK.Name);

Exception:

variable 'l1.OneToOne_Optional_FK' of type 'Microsoft.EntityFrameworkCore.Specification.Tests.TestModels.ComplexNavigationsModel.Level2' referenced from scope '', but it is not defined
at System.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage)
at System.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node)
at System.Linq.Expressions.ParameterExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection1 nodes) at System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression1 node)
at System.Linq.Expressions.Expression1.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 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 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 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 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 System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection1 nodes)
at System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression1 node) at System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator)
at System.Linq.Expressions.Expression1.Compile() Query\EntityQueryModelVisitor.cs(659,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateExecutorLambda[TResults]() Query\EntityQueryModelVisitor.cs(248,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel) Storage\Database.cs(67,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() Query\Internal\QueryCompiler.cs(213,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass19_01.b__0()
Query\Internal\CompiledQueryCache.cs(49,0): at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler) Query\Internal\QueryCompiler.cs(168,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQuery[TResult](Expression query) Query\Internal\QueryCompiler.cs(98,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) Query\Internal\EntityQueryProvider.cs(57,0): at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) at Remotion.Linq.QueryableBase1.GetEnumerator()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

@rowanmiller rowanmiller added this to the 1.1.0 milestone Oct 3, 2016
@maumar maumar modified the milestones: 1.2.0, 1.1.0 Oct 5, 2016
@smitpatel
Copy link
Contributor

Exception message changed here

 Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.ComplexNavigationsQuerySqlServerTest.Optional_navigation_take_optional_navigation [FAIL]
      System.InvalidCastException : Unable to cast object of type 'System.Linq.Expressions.UnaryExpression' to type 'Microsoft.EntityFrameworkCore.Query.Expressions.AliasExpression'.
      Stack Trace:
           at System.Linq.Enumerable.<CastIterator>d__94`1.MoveNext()
        src\Microsoft.EntityFrameworkCore.Relational\Query\Expressions\SelectExpression.cs(937,0): at Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpression.ExplodeStarProjection()
        src\Microsoft.EntityFrameworkCore.Relational\Query\RelationalQueryModelVisitor.cs(1076,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.QuerySourceUpdater.VisitConstant(ConstantExpression constantExpression)
        src\Microsoft.EntityFrameworkCore\Query\ExpressionVisitors\ExpressionVisitorBase.cs(26,0): at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.Visit(Expression node)
           at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](ReadOnlyCollection`1 nodes, String callerName)
        src\Microsoft.EntityFrameworkCore.Relational\Query\RelationalQueryModelVisitor.cs(1084,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.QuerySourceUpdater.VisitMethodCall(MethodCallExpression methodCallExpression)
        src\Microsoft.EntityFrameworkCore\Query\ExpressionVisitors\ExpressionVisitorBase.cs(26,0): at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.Visit(Expression node)
           at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](ReadOnlyCollection`1 nodes, String callerName)
        src\Microsoft.EntityFrameworkCore.Relational\Query\RelationalQueryModelVisitor.cs(1084,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.QuerySourceUpdater.VisitMethodCall(MethodCallExpression methodCallExpression)
        src\Microsoft.EntityFrameworkCore\Query\ExpressionVisitors\ExpressionVisitorBase.cs(26,0): at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.Visit(Expression node)
        src\Microsoft.EntityFrameworkCore.Relational\Query\RelationalQueryModelVisitor.cs(1021,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.LiftSubQuery(IQuerySource querySource, Expression itemsExpression, Expression expression)
        src\Microsoft.EntityFrameworkCore.Relational\Query\RelationalQueryModelVisitor.cs(412,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.CompileMainFromClauseExpression(MainFromClause mainFromClause, QueryModel queryModel)
        src\Microsoft.EntityFrameworkCore\Query\EntityQueryModelVisitor.cs(737,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel)
           at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
        src\Microsoft.EntityFrameworkCore\Query\EntityQueryModelVisitor.cs(718,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
        src\Microsoft.EntityFrameworkCore.Relational\Query\RelationalQueryModelVisitor.cs(374,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
        src\Microsoft.EntityFrameworkCore.SqlServer\Query\Internal\SqlServerQueryModelVisitor.cs(92,0): at Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
        src\Microsoft.EntityFrameworkCore\Query\EntityQueryModelVisitor.cs(260,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
        src\Microsoft.EntityFrameworkCore\Storage\Database.cs(67,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()
        src\Microsoft.EntityFrameworkCore\Query\Internal\QueryCompiler.cs(164,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, INodeTypeProvider nodeTypeProvider, IDatabase database, ILogger logger, Type contextType)
        src\Microsoft.EntityFrameworkCore\Query\Internal\QueryCompiler.cs(102,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_0`1.<Execute>b__0()
        src\Microsoft.EntityFrameworkCore\Query\Internal\CompiledQueryCache.cs(68,0): at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
        src\Microsoft.EntityFrameworkCore\Query\Internal\CompiledQueryCache.cs(45,0): at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
        src\Microsoft.EntityFrameworkCore\Query\Internal\QueryCompiler.cs(99,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
        src\Microsoft.EntityFrameworkCore\Query\Internal\EntityQueryProvider.cs(57,0): 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)
        src\Microsoft.EntityFrameworkCore.Specification.Tests\ComplexNavigationsQueryTestBase.cs(2213,0): at Microsoft.EntityFrameworkCore.Specification.Tests.ComplexNavigationsQueryTestBase`2.Optional_navigation_take_optional_navigation()
        test\Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests\ComplexNavigationsQuerySqlServerTest.cs(1869,0): at Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests.ComplexNavigationsQuerySqlServerTest.Optional_navigation_take_optional_navigation()
  Finished:    Microsoft.EntityFrameworkCore.SqlServer.FunctionalTests

tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 4, 2017
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 4, 2017
This reverts commit f735d79.
There was still a failure in InMemory that I missed
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 6, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#5230
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 6, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#5230
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 6, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 6, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 7, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
tuespetre added a commit to tuespetre/EntityFramework that referenced this issue Feb 9, 2017
…ated

SQL

- Resolves dotnet#2341
- Resolves dotnet#5085
- Resolves dotnet#6618
- Resolves dotnet#6647
- Resolves dotnet#6782
- Resolves dotnet#7080
- Resolves dotnet#7220
- Resolves dotnet#7417
- Resolves dotnet#7497
- Resolves dotnet#7523
- Resolves dotnet#7525
@maumar
Copy link
Contributor Author

maumar commented Apr 5, 2017

This now works in relational but fails for InMemory:

System.InvalidOperationException : Nullable object must have a value.
	at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
	at lambda_method(Closure , TransparentIdentifier`2 )
	at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
	at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
	at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
	at System.Linq.Enumerable.<TakeIterator>d__24`1.MoveNext()
	at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
	C:\git\EntityFramework\src\EFCore\Query\Internal\LinqOperatorProvider.cs(147,0): at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
	at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
	at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

@smitpatel
Copy link
Contributor

Exception msg - Nullable object must have a value. then why it is nullable object. :trollface:

@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Apr 19, 2017
maumar added a commit that referenced this issue May 17, 2017
…ueries projecting optional navigation, paging and another projecting of optional navigation

Issue has been already fixed in the earlier checkin, but the test was incorrect and would fail for InMemory regardless - fixing the test and enabling it.
@maumar maumar changed the title Query :: compilation error for queries projecting optional navigation, paging and another projecting of optional navigation Query: compilation error for queries projecting optional navigation, paging and another projecting of optional navigation May 17, 2017
@maumar
Copy link
Contributor Author

maumar commented May 17, 2017

product issue fixed in earlier checkin, test issue fixed in aba976c

@maumar maumar closed this as completed May 17, 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 May 17, 2017
@maumar maumar modified the milestones: 2.0.0-preview2, 2.0.0 May 17, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview2, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-test 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

4 participants