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 : Client GroupBy with anonymous key fails in binding #11973

Closed
smitpatel opened this issue May 11, 2018 · 2 comments
Closed

Query : Client GroupBy with anonymous key fails in binding #11973

smitpatel opened this issue May 11, 2018 · 2 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. regression type-bug
Milestone

Comments

@smitpatel
Copy link
Member

                var actual = context.Set<Order>()
                    .GroupBy(o => new { o.CustomerID, o.OrderDate })
                    .Select(g => new { g.Key, g })
                    .ToList()

Fails with

Test 'Microsoft.EntityFrameworkCore.Query.GroupByQuerySqlServerTest.GroupBy_anonymous_key_without_aggregate' failed: System.ArgumentException : Argument type '<>f__AnonymousType70`1[System.String]' does not match the corresponding member type 'System.String'
	at System.Linq.Expressions.Expression.ValidateNewArgs(ConstructorInfo constructor, ReadOnlyCollection`1& arguments, ReadOnlyCollection`1& members)
	at System.Linq.Expressions.Expression.New(ConstructorInfo constructor, IEnumerable`1 arguments, IEnumerable`1 members)
	at System.Linq.Expressions.NewExpression.Update(IEnumerable`1 arguments)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.MemberAccessBindingExpressionVisitor.VisitNew(NewExpression expression)
	at System.Linq.Expressions.NewExpression.Accept(ExpressionVisitor visitor)
	at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
	at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.MemberAccessBindingExpressionVisitor.VisitNew(NewExpression expression)
	at System.Linq.Expressions.NewExpression.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.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)
	at Microsoft.EntityFrameworkCore.Query.GroupByQueryTestBase`1.GroupBy_anonymous_key_without_aggregate()
	at Microsoft.EntityFrameworkCore.Query.GroupByQuerySqlServerTest.GroupBy_anonymous_key_without_aggregate()

Symptoms:
Any group by which will be evaluated on client and has anonymous type key will fail.
No work-arounds

@ajcvickers
Copy link
Member

@smitpatel Can you point to the place (PR, issue, or commit) where we introduced this break?

smitpatel added a commit that referenced this issue May 11, 2018
Issue: We have custom logic to map the anonymous key in selector to translate key for SQL Group By case which was being applied for client group by causing error during client binding.
Fix for this makes sure that when we do such transformation we are dealing with ShapedQuery only.

Resolves #11973
@smitpatel
Copy link
Member Author

@ajcvickers PR #11222

@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 11, 2018
@maumar maumar closed this as completed in 37b0cd0 May 11, 2018
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. regression type-bug
Projects
None yet
Development

No branches or pull requests

2 participants