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 (value does not fall within expected range) for query with order by, skip, another orderby and group aggregate #12805

Closed
maumar opened this issue Jul 25, 2018 · 2 comments · Fixed by #18283
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 25, 2018

query:

                var query = ctx.Orders.OrderBy(o => o.OrderID)
                        .Skip(80)
                        .OrderBy(gg => gg.CustomerID)
                        .GroupBy(o => o.CustomerID)
                        .Select(g => g.Average(o => o.OrderID));

                var result = query.ToList();

query model (at the time of error):

from IGrouping<string, Order> g in 
    (from Order gg in 
        (from Order o in DbSet<Order>
        order by [o].OrderID asc
        select [o]).Skip(__p_0)
    order by [gg].CustomerID asc
    select [gg]).GroupBy([gg].CustomerID, [gg])
select 
    (from Order o in [g]
    select [o].OrderID).Average()

subquery that is being visited when exception happens:

(from Order o in [g]
select [o].OrderID).Average()

_expression is expected to be of a sequence type, but in fact it's typed as ValueBuffer

exception:

Value does not fall within the expected range.
	at System.SharedTypeExtensions.GetSequenceType(Type type)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel)
	at Remotion.Linq.Clauses.MainFromClause.Accept(IQueryModelVisitor visitor, 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.RelationalQueryModelVisitor.VisitSubQueryModel(QueryModel queryModel)
	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)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitor.Visit(Expression expression)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalProjectionExpressionVisitor.Visit(Expression expression)
	at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
	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)
	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)
@ajcvickers ajcvickers added this to the 3.0.0 milestone Jul 30, 2018
@smitpatel
Copy link
Member

Dependent on #12089

@divega
Copy link
Contributor

divega commented Jun 24, 2019

As per triage discussion, removing propose-punt label. IIRC, we said we believe this will be fixed for 3.0.

@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jun 28, 2019
@smitpatel smitpatel added the verify-fixed This issue is likely fixed in new query pipeline. label Jul 2, 2019
@smitpatel smitpatel removed their assignment Aug 7, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 3.1.0 Sep 4, 2019
@maumar maumar added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed verify-fixed This issue is likely fixed in new query pipeline. punted-for-3.0 labels Oct 7, 2019
@maumar maumar modified the milestones: 3.1.0, 3.0.0 Oct 7, 2019
maumar added a commit that referenced this issue Oct 8, 2019
- added regression tests for #12289
- added regression tests for #15279
- added regression tests for #15938
- added regression tests for #18267

- resolves #12522
- resolves #12805
- resolves #13231
- resolves #13594
- resolves #13754
- resolves #14851
- resolves #15103
- resolves #15669
- resolves #15853
maumar added a commit that referenced this issue Oct 8, 2019
- added regression tests for #12289
- added regression tests for #15279
- added regression tests for #15938
- added regression tests for #18267

- resolves #12522
- resolves #12805
- resolves #13231
- resolves #13594
- resolves #13754
- resolves #14851
- resolves #15103
- resolves #15669
- resolves #15853
maumar added a commit that referenced this issue Oct 8, 2019
- added regression tests for #12289
- added regression tests for #15279
- added regression tests for #15938
- added regression tests for #18267

- resolves #12522
- resolves #12805
- resolves #13231
- resolves #13594
- resolves #13754
- resolves #14851
- resolves #15103
- resolves #15669
- resolves #15853
maumar added a commit that referenced this issue Oct 8, 2019
- added regression tests for #12289
- added regression tests for #15279
- added regression tests for #15938
- added regression tests for #18267

- resolves #12522
- resolves #12805
- resolves #13231
- resolves #13594
- resolves #13754
- resolves #14851
- resolves #15103
- resolves #15669
- resolves #15853
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.

4 participants