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

Processing of the LINQ expression 'GroupByShaperExpression ... by 'RelationalProjectionBindingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core #24695

Closed
larsholm opened this issue Apr 20, 2021 · 3 comments

Comments

@larsholm
Copy link
Contributor

Simple join followed by a group by produces the posted exception. The code in repo is heavily reduced from original.

What we have tried: Rewrite to let statement, using Navigation Properties, using latest preview. Unfortunately we cannot ToList or similar, as this later gets paged. ToList in Select does not work either.

Repo: https://github.com/larsholm/EFrepo
Run CreateSQLObjects.sql before building and running project. Change conn string in TMG2_ALWContext.cs:36

TMG2_ALWContext context = new TMG2_ALWContext();

            IQueryable<CountryGroupToEquityFactor> query =
                from
                    CountryGroupToEquityFactor record
                in
                    context.Set<CountryGroupToEquityFactor>()
                select
                    record
                ;

            IQueryable<CountryGroupToEquityFactorOutDto> result =
                from
                    CountryGroupToEquityFactor model
                in
                    query
                join
                    CountryGroupToEquityFactorView v
                in
                    context.Set<CountryGroupToEquityFactorView>()
                on
                    model.RecordId equals v.RecordId
                group v by new { model.RecordId, v.CountryGroupRatingCurrencyRecordId, v.CountryGroupId, v.CurrencyId, v.RatingSchemeRecordId, v.SchemeName, v.Default } into temp
                select
                    new CountryGroupToEquityFactorOutDto()
                    {
                        CountryGroupId = temp.Key.CountryGroupId,
                        CurrencyId = temp.Key.CurrencyId,
                        RatingSchemeRecordId = temp.Key.RatingSchemeRecordId,
                        RecordId = temp.Key.CountryGroupRatingCurrencyRecordId,
                        SchemeName = temp.Key.SchemeName,
                        DefaultGroup = temp.Key.Default,
                        EquityFactorValues = (from t in temp
                                              select new EquityFactorValuesOutDto
                                              {
                                                  EquityFactorId = t.EquityFactorId,
                                                  FromAmountInclusive = t.FromAmountInclusive,
                                                  RecordId = t.RecordId,
                                                  Rank = t.Rank,
                                                  EquityFactorRecordId = t.EquityFactorRecordId
                                              })
                    };

Include stack traces

System.InvalidOperationException
  HResult=0x80131509
  Message=Processing of the LINQ expression 'GroupByShaperExpression:
KeySelector: new { 
    RecordId = c.RecordId, 
    CountryGroupRatingCurrencyRecordId = c.CountryGroupRatingCurrencyRecordId, 
    CountryGroupId = c.CountryGroupId, 
    CurrencyId = c.CurrencyId, 
    RatingSchemeRecordId = c.RatingSchemeRecordId, 
    SchemeName = c.SchemeName, 
    Default = c.Default
 }, 
ElementSelector:EntityShaperExpression: 
    EntityType: CountryGroupToEquityFactorView Keyless
    ValueBufferExpression: 
        ProjectionBindingExpression: EmptyProjectionMember
    IsNullable: True
' by 'RelationalProjectionBindingExpressionVisitor' failed. This may indicate either a bug or a limitation in Entity Framework. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.
  Source=Microsoft.EntityFrameworkCore.Relational
  StackTrace:
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitExtension(Expression extensionExpression)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitMemberAssignment(MemberAssignment memberAssignment)
   at System.Linq.Expressions.ExpressionVisitor.VisitMemberBinding(MemberBinding node)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitMemberInit(MemberInitExpression memberInitExpression)
   at System.Linq.Expressions.MemberInitExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Translate(SelectExpression selectExpression, Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
   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 System.Linq.Queryable.Count[TSource](IQueryable`1 source)
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\dev\Downloads\ConsoleApp1\ConsoleApp1\ConsoleApp1\Program.cs:line 57

Include provider and version information

EF Core version: 5.0.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Win 10
IDE: Visual Studio 2019 16.10.0 Preview 2.0

@smitpatel
Copy link
Contributor

EquityFactorValues is term in projection after group by which doesn't apply aggregate. It is limitation of GroupBy currently that you can only select key terms or aggregate operation over grouping in projection after group by.

@ajcvickers
Copy link
Member

@smitpatel to de-dupe.

@smitpatel
Copy link
Contributor

Duplicate of #13805

@smitpatel smitpatel marked this as a duplicate of #13805 Apr 23, 2021
@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

3 participants