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: runtime error for Groupby on shadow property with First and OrderBy the result afterwards #12601

Closed
maumar opened this issue Jul 7, 2018 · 3 comments

Comments

@maumar
Copy link
Contributor

maumar commented Jul 7, 2018

query:

ctx.Employees
   .GroupBy(e => EF.Property<string>(e, "Title"))
   .Select(g => EF.Property<string>(g.First(), "Title"))
   .OrderBy(e => e);

query plan:

(QueryContext queryContext) => IEnumerable<string> _InterceptExceptions(
|__ source: IEnumerable<string> _ShapedQuery(
|   |__ queryContext: queryContext, 
|   |__ shaperCommandContext: SelectExpression: 
|   |       SELECT [e].[Title]
|   |       FROM [Employees] AS [e]
|   |       GROUP BY [e].[Title]
|   |       ORDER BY [e].[Title], 
|   |__ shaper: (QueryContext queryContext | ValueBuffer g) => string GetValue(
|       |__ queryContext: queryContext, 
|       |__ entity: (Employee)Employee TryReadValue(g, 0, Employee.Title), 
|       |__ property: Employee.Title)), 
|__ contextType: TestModels.Northwind.NorthwindRelationalContext, 
|__ logger: DiagnosticsLogger<Query>, 
|__ queryContext: Unhandled parameter: queryContext)

exception:

Unable to cast object of type 'System.String' to type 'Microsoft.EntityFrameworkCore.TestModels.Northwind.Employee'.
	at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityMaterializerSource.TryReadValue[TValue](ValueBuffer& valueBuffer, Int32 index, IPropertyBase property)
	at lambda_method(Closure , QueryContext , ValueBuffer )
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.ProjectionShaper.TypedProjectionShaper`3.Shape(QueryContext queryContext, ValueBuffer& valueBuffer)
	at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.ProjectionShaper.TypedProjectionShaper`3.Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.IShaper<TOut>.Shape(QueryContext queryContext, ValueBuffer& valueBuffer)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
	at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
	at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
	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)
	at Microsoft.EntityFrameworkCore.Query.GroupByQueryTestBase`1.GroupBy_Shadow(Boolean isAsync)
	at Microsoft.EntityFrameworkCore.Query.GroupByQuerySqlServerTest.<>n__142(Boolean isAsync)
	at Microsoft.EntityFrameworkCore.Query.GroupByQuerySqlServerTest.<GroupBy_Shadow>d__147.MoveNext()
	--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
	--- End of stack trace from previous location where exception was thrown ---
	at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
	at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
@divega divega added this to the 2.2.0 milestone Jul 11, 2018
@divega
Copy link
Contributor

divega commented Jul 11, 2018

@maumar to make sure we can fix this in RequiresMaterializationExpressionVisitor.

@smitpatel
Copy link
Member

Related #12089

@smitpatel
Copy link
Member

Merged into #13805

@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