Skip to content

Avoid applying null semantics expansion to joins between composite keys #16265

Closed

Description

@divega

In the discussion at #15798 (comment), we agreed that we will stick to the principle that when we traverse relationships (essentially, performing an equality comparisons between keys), null values should not be considered equal, therefore we should not use null semantics.

This principle applies to anything generated by navigation expansion, as well as to ad-hoc relationships established by join operations.

In LINQ to Objects, Join() for simple keys follows this same rule: two values of a nullable type that are null are not considered a match. But for anything more complicated, Join() relies on the equality comparer at hand, which is usually implemented using null semantics. For examples, a join between new {A = 1, B = null} and new {A = 1, B = null} is a match because the comparer of anonymous types just performs member by member comparison with client null semantics.

Join between composite keys in LINQ usually ends up being represented as joins between structural types, and hence when we translate them to SQL, we currently go out of our way to try to replicate the behavior of LINQ to objects.

I believe that doing so can produce unnecessarily complex queries and also results that don't align with how composite key joins normally work on databases.

Activity

  1. added this to the Backlog milestone on Jun 28, 2019
  2. maumar commented on Dec 5, 2019

    @maumar
    Contributor

    this is fixed now

  3. modified the milestones: Backlog, 3.1.0 on Dec 5, 2019
  4. self-assigned this
    on Dec 5, 2019
  5. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions