Query regression in preview 9: Combination of GroupBy, aggregate and let throws
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the reported LINQ query and the RelationalProjectionBindingExpressionVisitor failure, comparing the Preview 8 and Preview 9 translation behavior. Reproduce the GroupBy, aggregate, let, where, and orderby combination, then add or update coverage so the query translates successfully and produces the expected grouped SQL.
Written by the indexing model from the issue text.
Description
This was reported in the Preview 9 blog post:
This LINQ statement (and other similar statements) was being translated properly till Preview 8:
var queryYearly =
from h in context.Histories.AsNoTracking() group h by h.HistoryDate.Year into yearGroup
orderby yearGroup.Key descending
let Total = yearGroup.Sum(m => m.Fee)
where Total > 0
select new
{
Year = yearGroup.Key,
Total
};
Updated to preview 9 this morning and I am getting the following error:
System.InvalidOperationException HResult=0x80131509 Message=Processing of the LINQ expression 'GroupBy(KeySelector: DATEPART(year, h.HistoryDate), ElementSelector:EntityShaperExpression: EntityType: Histories ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False)' by 'RelationalProjectionBindingExpressionVisitor' failed.....
According to @smitpatel:
Let throws us off. If you remove let then it works:
SELECT DATEPART(year, [b].[HistoryDate]) AS [Year], SUM([b].[Fee]) AS [Total]
FROM [Blogs] AS [b]
GROUP BY DATEPART(year, [b].[HistoryDate])
HAVING SUM([b].[Fee]) > 0
ORDER BY DATEPART(year, [b].[HistoryDate]) DESC
With let the expression we get is:
value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[EFSampleApp.Blog]).AsNoTracking().GroupBy(h => h.HistoryDate.Year).OrderByDescending(yearGroup => yearGroup.Key).Select(yearGroup => new <>f__AnonymousType0`2(yearGroup = yearGroup, Total = yearGroup.Sum(m => m.Fee))).Where(<>h__TransparentIdentifier0 => (<>h__TransparentIdentifier0.Total > 0)).Select(<>h__TransparentIdentifier0 => new <>f__AnonymousType1`2(Year = <>h__TransparentIdentifier0.yearGroup.Key, Total = <>h__TransparentIdentifier0.Total))
Since Select contains reference to grouping which cannot be put in Projection in SelectExpression we throw.
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100