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

The LINQ expression GroupByShaperExpression could not be translated #17878

Closed
IgorMenshikov opened this issue Sep 17, 2019 · 2 comments
Closed
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported

Comments

@IgorMenshikov
Copy link

IgorMenshikov commented Sep 17, 2019

At my .NET 2.2. application, I have a table named Operation mapped to a class.

It has a query:

var exportHash = (from i in context.Operation
                              where i.DeleteDate == null
                                 && exportTypeList.Contains(i.Type)
                                 && i.Status == OperationStatus.Code.Completed
                                 && i.ParentOperationID != null
                                 && operationIDList.Contains(i.ParentOperationID.Value)
                              orderby i.ProcessDate descending
                              group i by i.ParentOperationID into g
                              select new
                              {
                                  ID = g.Key,
                                  List = g.ToList()
                              }).ToDictionary(i => i.ID, i => i.List);

On 2.2 this query works but on 3.0.0-rc1, it gives an exception:

System.InvalidOperationException: 'The LINQ expression 'ToList<Operation>(GroupByShaperExpression:
KeySelector: o.ParentOperationID, 
ElementSelector:EntityShaperExpression: 
    EntityType: Operation
    ValueBufferExpression: 
        ProjectionBindingExpression: EmptyProjectionMember
    IsNullable: False
)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). 

I am not sure why the grouping fails.

Operation class is quite simple:

    [Table("Operation")]
    public class Operation
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Column("OperationID")]
        public int ID { get; set; }

        [Column("OperationTypeID")]
        public OperationType.Code Type { get; set; }

        [Column("OperationStatusID")]
        public OperationStatus.Code Status { get; set; }

        [Column]
        public int? ParentOperationID { get; set; }

        [Column]
        public DateTime? DeleteDate { get; set; }

        [Column]
        public DateTime PlanDate { get; set; }

        [Column]
        public DateTime? ProcessDate { get; set; }

        [Column]
        public int? PeriodID { get; set; }
}

Further technical details

EF Core version: 3.0.0-rc1.19456.14
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.3 Preview 4

@smitpatel
Copy link
Contributor

smitpatel commented Sep 17, 2019

Possibly same root cause as #17342

The GroupBy may be simple but it does not correspond to a SQL Group By. You are doing grouping.ToList(). That requires client side group by operator to generate groupings.

Duplicate of #17068

@IgorMenshikov
Copy link
Author

You are right. Thanks for the explanation.

@smitpatel smitpatel added closed-no-further-action The issue is closed and no further action is planned. type-bug and removed type-bug labels Sep 17, 2019
@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
Labels
closed-no-further-action The issue is closed and no further action is planned. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants