Repository navigation
Fix #3570: Support empty collection when using Contains (#3573) - #3602
Merged
Merged
Conversation
* Fix #3570: Support empty collection when using Contains LINQ queries such as 'skus.Contains(x.Sku)' translate to an OData 'in' filter. When the source collection is empty, the client threw InvalidOperationException (ALinq_ContainsNotValidOnEmptyCollection) instead of producing a valid query. Emit the empty 'in' collection literal (e.g. 'Name in ()') for an empty collection. The OData query parser already supports this form and evaluates it to no matches, so the query now returns an empty result set instead of failing. Updated the two client tests that asserted the old throwing behavior to verify the new 'in ()' translation. * Remove unused ALinq_ContainsNotValidOnEmptyCollection resource string Address PR review comment: the resource string is no longer referenced after allowing empty collections in Contains. Remove it from SRResources.resx, SRResources.Designer.cs, and the SRResourcesTests InlineData.
xuzhg
requested review from
WanjohiSammy
and
a lite review from Copilot
and removed request for
Copilot
August 25, 2026 19:15
Contributor
Author
|
/AzurePipelines run |
There was a problem hiding this comment.
Pull request overview
Updates the OData Client LINQ-to-URI translation so Enumerable.Contains(...) over an empty in-memory collection no longer throws, and instead emits an empty in collection literal (in ()) which the OData URI parser treats as “matches nothing”.
Changes:
- Translate empty
Containssource collections toin ()instead of throwingInvalidOperationException. - Update client translation unit tests for string and enum cases to assert the new
in ()output. - Remove the now-unused
ALinq_ContainsNotValidOnEmptyCollectionresource and its test coverage entry.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.OData.Client.Tests/Resources/SRResourcesTests.cs | Removes the resource key from the resource-string validation test data. |
| test/UnitTests/Microsoft.OData.Client.Tests/DataServiceQueryProviderTests.cs | Updates LINQ translation tests to expect Name in () / Color in () instead of exceptions. |
| src/Microsoft.OData.Client/SRResources.resx | Deletes the unused ALinq_ContainsNotValidOnEmptyCollection string resource. |
| src/Microsoft.OData.Client/SRResources.Designer.cs | Removes the generated accessor property for the deleted resource key. |
| src/Microsoft.OData.Client/ALinq/ExpressionWriter.cs | Changes Contains list-literal serialization to allow empty collections and emit (). |
Files not reviewed (1)
- src/Microsoft.OData.Client/SRResources.Designer.cs: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LINQ queries such as 'skus.Contains(x.Sku)' translate to an OData 'in' filter. When the source collection is empty, the client threw InvalidOperationException (ALinq_ContainsNotValidOnEmptyCollection) instead of producing a valid query.
Emit the empty 'in' collection literal (e.g. 'Name in ()') for an empty collection. The OData query parser already supports this form and evaluates it to no matches, so the query now returns an empty result set instead of failing.
Updated the two client tests that asserted the old throwing behavior to verify the new 'in ()' translation.
Address PR review comment: the resource string is no longer referenced after allowing empty collections in Contains. Remove it from SRResources.resx, SRResources.Designer.cs, and the SRResourcesTests InlineData.
Ports the #3570 fix from
dev-9.xtomain.LINQ queries such as
skus.Contains(x.Sku)translate to an ODatainfilter. Previously, an empty source collection caused the client to throw
InvalidOperationException.This change:
incollection, such asName in ().ALinq_ContainsNotValidOnEmptyCollectionresource.The OData.NET URI parser already supports empty
incollections and evaluatesthem as matching no values.
Issues
This pull request fixes #xxx.
Description
Briefly describe the changes of this pull request.
Checklist (Uncheck if it is not completed)
Additional work necessary
If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.
Repository notes
Team members can start a CI build by adding a comment with the text
/AzurePipelines runto a PR. A bot may respond indicating that there is no pipeline associated with the pull request. This can be ignored if the build is triggered.Team members should not trigger a build this way for pull requests coming from forked repositories. They should instead trigger the build manually by setting the "branch" to
refs/pull/{prId}/mergewhere{prId}is the ID of the PR.