Skip to content

Conversation

@BurakBebek1
Copy link

@BurakBebek1 BurakBebek1 commented Jan 31, 2026

…on SQL Server

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

Summary of the changes

  • Added logic to handle null values when translating collection parameters using OPENJSON on SQL Server.
  • When a collection contains a null element, the generated SQL now includes an OR [column] IS NULL clause to ensure NULL rows are correctly matched, consistent with LINQ Contains behavior.
  • This fix specifically targets scenarios where the 2100 parameter limit is exceeded and the query switches to JSON-based parameterization.

Fixes #37605

@BurakBebek1 BurakBebek1 requested a review from a team as a code owner January 31, 2026 16:36
@BurakBebek1
Copy link
Author

@dotnet-policy-service agree

@BurakBebek1
Copy link
Author

Here is the generated SQL for the fix. As shown below, it correctly handles null values by adding the OR ... IS NULL clause when using OPENJSON.
Screenshot_1

@roji
Copy link
Member

roji commented Jan 31, 2026

@BurakBebek1 above you referenced issue #37494, which seems unrelated. If there's a bug here and there isn't yet an issue tracking it, can you please open a new issue with a clear repro (currently behavior/SQL and how it's wrong)?

@BurakBebek1
Copy link
Author

@roji Hi,
I have created a dedicated issue for this bug: #37605. It includes a minimal reproduction test case and the full stack traces for both the InvalidCastException (at execution) and UnreachableException (during translation). This PR addresses the missing nullability handling when OPENJSON is used for large collections.
Thank you.

@BurakBebek1 BurakBebek1 changed the title Fix #37494: Handle null values in IN expressions when using OPENJSON … Fix #37605: Handle null values in IN expressions when using OPENJSON … Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: UnreachableException in SqlServerSqlNullabilityProcessor when using OPENJSON with a collection containing null

2 participants