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

Grouping produces wrong query when nested navigation is used #13594

Closed
msmolka opened this issue Oct 11, 2018 · 1 comment · Fixed by #18283
Closed

Grouping produces wrong query when nested navigation is used #13594

msmolka opened this issue Oct 11, 2018 · 1 comment · Fixed by #18283
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@msmolka
Copy link

msmolka commented Oct 11, 2018

Grouping produces wrong query.

I have following model:

Steps to reproduce

public class Model
{
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public Guid Id { get; set; }

        public Guid? EngineerId { get; set; }

        public virtual User Engineer { get; set; }

        public Guid? TakenBy { get; set; } 
        
        [ForeignKey("TakenBy")]
        public virtual User TakenByUser { get; set; }      

        public Guid? LockedBy { get; set; } 
        
        [ForeignKey("LockedBy")]
        public virtual User LockedByUser { get; set; }

        public string Name { get; set; }
}

then I have selector

from model in db.Models
select new {
    Id = model.Id,
    EngineerName = model.Engineer.DisplayName,
    TakenByName =  model.TakenByUser.DisplayName,
    LockedByName = model.LockedByUser.DisplayName 
}

all is working properly when it comes to sorting or filtering
however when I'm trying to group .e.g. by name group by produces wrong select.
It reproduces in this case:

    ...
    [t1].[EngineerName],
    [t1].[TakenByName],
    [t1].[LockedByName],
   
    ...

    [t1].[DisplayName],
    [t1].[DisplayName],
    [t1].[DisplayName]

at the end of SQL select part of group
which is not exist in from select which is causing SQL exception:

System.Data.SqlClient.SqlException (0x80131904): 

Invalid column name 'DisplayName'.
Invalid column name 'DisplayName'.
Invalid column name 'DisplayName'.

Further technical details

EF Core version: 2.1.4
Database Provider: (Microsoft.EntityFrameworkCore.SqlServer)
Operating system: Windows 10 Pro
IDE: (Visual Studio 2017 15.8.7)

@ajcvickers ajcvickers added this to the 3.0.0 milestone Oct 15, 2018
@divega divega modified the milestones: 3.0.0, Backlog Jun 21, 2019
@smitpatel smitpatel removed their assignment Jun 24, 2019
@AndriySvyryd AndriySvyryd added verify-fixed This issue is likely fixed in new query pipeline. and removed relinq-dependent labels Aug 22, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 3.1.0 Sep 4, 2019
@smitpatel
Copy link
Contributor

The query is missing in initial issue.
Just add a test with custom selector like that followed by group by.

@maumar maumar added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed verify-fixed This issue is likely fixed in new query pipeline. punted-for-3.0 labels Oct 8, 2019
@maumar maumar modified the milestones: 3.1.0, 3.0.0 Oct 8, 2019
maumar added a commit that referenced this issue Oct 8, 2019
- added regression tests for #12289
- added regression tests for #15279
- added regression tests for #15938
- added regression tests for #18267

- resolves #12522
- resolves #12805
- resolves #13231
- resolves #13594
- resolves #13754
- resolves #14851
- resolves #15103
- resolves #15669
- resolves #15853
maumar added a commit that referenced this issue Oct 8, 2019
- added regression tests for #12289
- added regression tests for #15279
- added regression tests for #15938
- added regression tests for #18267

- resolves #12522
- resolves #12805
- resolves #13231
- resolves #13594
- resolves #13754
- resolves #14851
- resolves #15103
- resolves #15669
- resolves #15853
maumar added a commit that referenced this issue Oct 8, 2019
- added regression tests for #12289
- added regression tests for #15279
- added regression tests for #15938
- added regression tests for #18267

- resolves #12522
- resolves #12805
- resolves #13231
- resolves #13594
- resolves #13754
- resolves #14851
- resolves #15103
- resolves #15669
- resolves #15853
maumar added a commit that referenced this issue Oct 8, 2019
- added regression tests for #12289
- added regression tests for #15279
- added regression tests for #15938
- added regression tests for #18267

- resolves #12522
- resolves #12805
- resolves #13231
- resolves #13594
- resolves #13754
- resolves #14851
- resolves #15103
- resolves #15669
- resolves #15853
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants