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: further improve translation of queries with Distinct or Groupby in correlated subquery, when entity identifiers are not easy to obtain #26077

Open
Tracked by #30173
maumar opened this issue Sep 16, 2021 · 0 comments

Comments

@maumar
Copy link
Contributor

maumar commented Sep 16, 2021

Improvement on #22049. Currently, when we don't have access to "natural" identifiers, (so we can't inject orderby to properly bucket the results in case of correlated subquery - this can happen for GroupBy and Distinct) we try to use what we have - entire projection in case of distinct and grouping key in case of GroupBy. Those still guarantee the uniqueness of the row, so it's ok to use them. However, current limitation is that we only do this if the entire projection is made of columns - we don't do it for anything more complex, say x.Name.Length. It should be perfectly fine to use more complex projection as it still guarantees the uniqueness of the row. The reason why we have the limitation is that we didn't have an easy way to get the proper comparer for this complex expression (in case of columns we use the comparer from type mapping).

Example of the query that could work: Correlated_collection_with_distinct_not_projecting_identifier_column_also_projecting_complex_expressions

ss.Set<Gear>()
                    .Select(
                        g => new
                        {
                            Key = g.Nickname,
                            Subquery = g.Weapons
                                .Select(w => new { w.Name, w.IsAutomatic, w.OwnerFullName.Length })
                                .Distinct().ToList()
                        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants