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

GroupBy does not seem to work over IQueryable #2003

Closed
Mhirji opened this issue Jan 4, 2020 · 2 comments
Closed

GroupBy does not seem to work over IQueryable #2003

Mhirji opened this issue Jan 4, 2020 · 2 comments

Comments

@Mhirji
Copy link

Mhirji commented Jan 4, 2020

It would appear that a query like this: $apply=groupby((disbursementYear),aggregate(disbursementAmount with sum as total)) which used to work under dotnet core 2.2, is not working when using dotnet core 3.1. I am getting IQueryable from the dbcontext and returning it via an Odata controller. I am not sure if this has to do with EF Core 3 not supporting client side processing or if I have missing something. I am guessing that if this was not an IQueryable it would work, but that would be a significant performance issue as some of our datasets are large. Any help would be.

Assemblies affected

*Microsoft.AspNetCore.OData 7.3.0
*Microsoft.EntityFrameworkCore 3.1
*Microsoft.EntityFrameworkCore.SqlServer 3.1

Reproduce steps

Return a sql table from a dbcontext as IQueryable to the controller and return the IQueryable from the controller.

Expected result

The response would be the result of the aggregation based on the gouping specified in the request.

Actual result

Error: Stack trace bellow.

Additional detail

*An unhandled exception occurred while processing the request.
InvalidOperationException: Processing of the LINQ expression '(GroupByShaperExpression:
KeySelector: new GroupByWrapper{ GroupByContainer = new LastInChain{
Name = (N'disbursementYear'),
Value = (object)(g.DisbursementYear)
}
}
,
ElementSelector:new FlatteningWrapper{
Source = (EntityShaperExpression:
EntityType: VGrantAgreementDisbursement
ValueBufferExpression:
(ProjectionBindingExpression: Source)
IsNullable: False
),
GroupByContainer = new LastInChain{
Name = (ProjectionBindingExpression: GroupByContainer.Name),
Value = (ProjectionBindingExpression: GroupByContainer.Value)
}

}
)' by 'RelationalProjectionBindingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitExtension(Expression extensionExpression)

Stack Query Cookies Headers Routing
InvalidOperationException: Processing of the LINQ expression '(GroupByShaperExpression: KeySelector: new GroupByWrapper{ GroupByContainer = new LastInChain{ Name = (N'disbursementYear'), Value = (object)(g.DisbursementYear) } } , ElementSelector:new FlatteningWrapper{ Source = (EntityShaperExpression: EntityType: VGrantAgreementDisbursement ValueBufferExpression: (ProjectionBindingExpression: Source) IsNullable: False ), GroupByContainer = new LastInChain{ Name = (ProjectionBindingExpression: GroupByContainer.Name), Value = (ProjectionBindingExpression: GroupByContainer.Value) } } )' by 'RelationalProjectionBindingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitExtension(Expression extensionExpression)
System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitMemberAssignment(MemberAssignment memberAssignment)
System.Linq.Expressions.ExpressionVisitor.VisitMemberBinding(MemberBinding node)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitMemberInit(MemberInitExpression memberInitExpression)
System.Linq.Expressions.MemberInitExpression.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitMemberAssignment(MemberAssignment memberAssignment)
System.Linq.Expressions.ExpressionVisitor.VisitMemberBinding(MemberBinding node)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitMemberInit(MemberInitExpression memberInitExpression)
System.Linq.Expressions.MemberInitExpression.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Translate(SelectExpression selectExpression, Expression expression)
Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor(Expression query)
Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery(Expression query, bool async)
Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore(IDatabase database, Expression query, IModel model, bool async)
Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler+<>c__DisplayClass12_0.b__0()
Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore(object cacheKey, Func<Func<QueryContext, TFunc>> compiler)
Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery(object cacheKey, Func<Func<QueryContext, TResult>> compiler)
Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync(Expression query, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync(Expression expression, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable.GetAsyncEnumerator(CancellationToken cancellationToken)
Microsoft.AspNetCore.Mvc.Infrastructure.AsyncEnumerableReader.ReadInternal(IAsyncEnumerable value)
Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsyncEnumerable(ActionContext context, ObjectResult result, IAsyncEnumerable asyncEnumerable)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|21_0(ResourceInvoker invoker, IActionResult result)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|29_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNet.OData.Batch.ODataBatchMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Show raw exception details.*

@hidegh
Copy link

hidegh commented Jan 5, 2020

@Mhirji this is due to EF core limitation and not OData related.

See: dotnet/efcore#10012

EF Core still is not able to do the same ORM stuff as EF 6.x nor as NHibernate from 2010 :)

@Mhirji
Copy link
Author

Mhirji commented Jan 5, 2020

Thanks @hidegh. I know they are behind, just thought this should work as it did before. Guess I'll have to revêt back to 2.2 and keep my fingers crossed I don't need support from MS. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants