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: Subquery projection being selected incorrectly with required navigation filter #6657

Closed
felipepessoto opened this issue Oct 1, 2016 · 3 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@felipepessoto
Copy link
Contributor

felipepessoto commented Oct 1, 2016

Steps to reproduce

Full example

EfCoreJoinIssue.zip

The issue

Running

IQueryable<Post> posts = db.Posts;
        posts = posts.Where(x => x.Author.UserName == "myuser");
        posts = posts.Take(5);

        var query = (from post in posts
                     select new { post.Slug, C = post.Comments.Count() });

Generates a query that joins using the wrong columns(or alias).

If we move Take(5) to the end, or remove the Where. It works:

IQueryable posts = db.Posts;
posts = posts.Where(x => x.Author.UserName == "myuser");
var query = (from post in posts
select new { post.Slug, C = post.Comments.Count() }).Take(5);

Or:

IQueryable posts = db.Posts;
posts = posts.Take(5);

        var query = (from post in posts
                     select new { post.Slug, C = post.Comments.Count() });
@smitpatel
Copy link
Contributor

Can you post the generated query?

@felipepessoto
Copy link
Contributor Author

felipepessoto commented Oct 1, 2016

They are in comments inside the code:

                //SELECT[t].[Slug], (
                //   SELECT COUNT(*)
                //          FROM[PostComments] AS[p0]
                //          WHERE[t].[Id] = [p0].[PostId]
                //      )
                //      FROM(
                //          SELECT TOP(@__p_0)[x.Author0].*  (my note: should be [x0].*)
                //          FROM[Posts] AS[x0]
                //          INNER JOIN[Users] AS[x.Author0] ON[x0].[AuthorId] = [x.Author0].[Id]
                //          WHERE[x.Author0].[UserName] = N'myuser'
                //      ) AS[t]

                //Error: Invalid column name 'Slug'.

@rowanmiller rowanmiller added this to the 1.1.0 milestone Oct 3, 2016
@maumar maumar modified the milestones: 1.1.0-preview1, 1.1.0 Oct 5, 2016
@rowanmiller rowanmiller modified the milestones: 1.2.0, 1.1.0-preview1 Oct 14, 2016
@smitpatel smitpatel modified the milestones: 1.1.0-preview1, 1.2.0 Oct 14, 2016
@smitpatel
Copy link
Contributor

@rowanmiller @divega - Bumping the milestone back & submitted PR.

@smitpatel smitpatel changed the title EF generating wrong SQL - Joining the wrong column Query: Subquery projection being selected incorrectly with required navigation filter Oct 14, 2016
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 17, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
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. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants