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

ArgumentException when SQLite database filter by aggregation property #14083

Closed
voronov-maxim opened this issue Dec 5, 2018 · 6 comments
Closed

Comments

@voronov-maxim
Copy link
Contributor

Exception message:
System.ArgumentException: 'Value does not fall within the expected range.'

Stack trace:
   at System.SharedTypeExtensions.GetSequenceType(Type type)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitMainFromClause(MainFromClause fromClause, 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.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitSubQuery(SubQueryExpression expression)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
   at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, 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)
--- End of stack trace from previous location where exception was thrown ---
   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.QueryCompiler.Execute[TResult](Expression query)
   at Remotion.Linq.QueryableBase`1.GetEnumerator()
   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 OdataToEntity.Test.Program.Main(String[] args) in E:\vorona\OdataToEntity\test\OdataToEntity.Test\Program.cs:line 14

Steps to reproduce

class OrderItem
{
  public int Id { get; set; }
  public int OrderId { get; set; }
  public Decimal? Price { get; set; }
}
dbContext.OrderItems.GroupBy(i => i.OrderId).Select(g => new { sum = g.Sum(i => i.Price) }).Where(a => a.sum > 1).ToArray();

All worked well with SqlServer provider.

Further technical details

EF Core version: 2.2.0
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: Windows 8.1
IDE: Visual Studio 2017 15.9.3

@smitpatel
Copy link
Contributor

Duplicate of #12089

@smitpatel smitpatel marked this as a duplicate of #12089 Dec 5, 2018
@smitpatel
Copy link
Contributor

I believe issue here is, SQLite is doing Sum on client since it's on decimal column but GroupBy aggregate pre-determines the translation and throws if anything goes wrong.

@voronov-maxim
Copy link
Contributor Author

No reproduce in previous version 2.1.1

@smitpatel
Copy link
Contributor

@voronov-maxim - Fixed as #10534 in 2.2

@voronov-maxim
Copy link
Contributor Author

@voronov-maxim - Fixed as #10534 in 2.2

This regression bug, no reproduced when sum by int

dbContext.OrderItems.GroupBy(i => i.OrderId).Select(g => new { sum = g.Sum(i => i.Id) }).Where(a => a.sum > 1).ToArray();

@smitpatel
Copy link
Contributor

@voronov-maxim - What I meant to say is, decimal computation on SQLite on server side can generate incorrect results. #10534 made it to evaluate on client to generate correct results. Which exposed the query to another bug #12089 hence you are seeing the issue. It does not happen in 2.1 since #10534 went to 2.2 release.

@divega divega closed this as completed Dec 7, 2018
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants