-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to #6366 - 2 level expand not working correctly
Problem happens for complex include scenarios like so: ctx .Posts.Include(x => x.User).ThenInclude(x => x.Roles) .Include(x => x.VoteDefinition).ThenInclude(x => x.PossibleAnswers) .Skip(1) We generate 3 queries for this case: first one gets Posts and 1:1 navigations (User and Vote Definition) SELECT [x].[Id], [x].[Name], [x].[UserId], [x].[VoteDefinitionId], [v].[Id], [v].[PostId], [u].[Id], [u].[Name] FROM [Posts] AS [x] LEFT JOIN [VoteDefinitions] AS [v] ON [v].[PostId] = [x].[Id] INNER JOIN [Users] AS [u] ON [x].[UserId] = [u].[Id] ORDER BY [v].[Id], [u].[Id] OFFSET @__p_0 ROWS',N'@__p_0 int second one copies the first one and joins it with Roles table to return associated Roles SELECT [r].[Id], [r].[Name], [r].[UserId] FROM [Roles] AS [r] INNER JOIN ( SELECT DISTINCT [t0].* FROM ( SELECT [v].[Id], [u].[Id] AS [Id0] FROM [Posts] AS [x] LEFT JOIN [VoteDefinitions] AS [v] ON [v].[PostId] = [x].[Id] INNER JOIN [Users] AS [u] ON [x].[UserId] = [u].[Id] ORDER BY [v].[Id], [u].[Id] OFFSET @__p_0 ROWS ) AS [t0] ) AS [u0] ON [r].[UserId] = [u0].[Id] ORDER BY [u0].[Id], [u0].[Id0]',N'@__p_0 int third one is similar to the second one. Problem is that in second query we are joining based on a wrong column (VoteDefinition's Id rather than User's Id). This is because we lose track of the information about which column is associated with which property. Due to Skip() call in the original LINQ query, we generate SELECT * around the relevant column information. Later, when looking for which column to join, we peek into the SELECT expression and don't see any information there so we assume that we should join based on a property with the name we need. This works fine if there are no duplicate columns with the same name projected out (and uniquefied) from other joined tables. Fix is, in case of a SELECT * query, to look for the relevant column information in the TablesExpressions/SelectExpressions that the SELECT * is projecting from.
- Loading branch information
Showing
3 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters