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: GroupBy add tests when grouping key is complex & aggregate is applied #16409

Open
smitpatel opened this issue Jul 2, 2019 · 1 comment
Assignees
Labels
area-query area-test punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Milestone

Comments

@smitpatel
Copy link
Member

See #12476

@ajcvickers ajcvickers added this to the Backlog milestone Jul 8, 2019
@ntierontime
Copy link

ntierontime commented Aug 5, 2019

EF.Functions.DateDiffDay is not translated properly when grouped by.

Personally, this is a standard usage.
The EF Query is translated to following sql:

SELECT DATEPART(year, [t].[RecordDate]) AS [Year], DATEPART(month, [t].[RecordDate]) AS [Month], @___DateTimeNow_1 AS [AverageVirtualAge]
FROM [dbo].[TouchLog] AS [t]
GROUP BY DATEPART(year, [t].[RecordDate]), DATEPART(month, [t].[RecordDate])
    public partial class TouchLog
    {
        public long TouchLogId { get; set; }
        public DateTime? RecordDate { get; set; }
    }
            DateTime _DateTimeNow = DateTime.Now;

            var report = from t in _dbContext.TouchLog
                    select new { Year = t.RecordDate.Value.Year, Month = t.RecordDate.Value.Month, RecordDate = t.RecordDate, VirtualAge = EF.Functions.DateDiffDay(t.RecordDate, _DateTimeNow) } into tNew
                    group new { t = tNew } by new { Year = tNew.Year, Month = tNew.Month } into tG
                    let _AverageVirtualAge = tG.Average(p => (double?)EF.Functions.DateDiffDay(p.t.RecordDate, _DateTimeNow))
                    //let _AverageVirtualAge = tG.Average(p => (double?)p.t.VirtualAge)
                    //let _AverageVirtualAge = tG.Select(p => (double?)p.t.VirtualAge).Average()
                    select new 
                    {
                        Year = tG.Key.Year,
                        Month = tG.Key.Month,
                        AverageVirtualAge = _AverageVirtualAge
                    } into vD6
                    select vD6;

@ajcvickers ajcvickers modified the milestones: Backlog, MQ Sep 11, 2020
@ajcvickers ajcvickers modified the milestones: MQ, 7.0.0 Jan 21, 2022
@ajcvickers ajcvickers added the punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. label Aug 11, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, Backlog Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query area-test punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-enhancement
Projects
None yet
Development

No branches or pull requests

4 participants