Repository navigation
Fix handling of Contains on IReadOnlySet and custom IReadOnlyCollection. - #37390
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the handling of Contains method calls on IReadOnlySet<T> and custom IReadOnlyCollection<T> implementations by expanding the query normalization logic to recognize Contains methods defined on IReadOnlyCollection<T> in addition to ICollection<T>.
Key Changes:
- Extended the
QueryableMethodNormalizingExpressionVisitorto detect and convertContainscalls onIReadOnlyCollection<T>types - Added comprehensive test coverage for
IReadOnlySet<T>and custom read-only collection types withContainsmethods - Updated SQL baselines across all provider test suites to reflect proper query translation
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/EFCore/Query/Internal/QueryableMethodNormalizingExpressionVisitor.cs | Extended Contains method detection to include IReadOnlyCollection<> types alongside ICollection<> |
| test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs | Added test methods for IReadOnlySet and ReadOnlyCollectionWithContains, plus helper class for custom read-only collection |
| test/EFCore.Sqlite.FunctionalTests/Query/PrimitiveCollectionsQuerySqliteTest.cs | Added SQL baselines for SQLite provider showing proper IN clause generation |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs | Added SQL baselines for SQL Server provider |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerJsonTypeTest.cs | Added SQL baselines for SQL Server with JSON types |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServer160Test.cs | Added SQL baselines for SQL Server 160 compatibility |
| test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQueryOldSqlServerTest.cs | Added SQL baselines for older SQL Server versions |
| test/EFCore.Cosmos.FunctionalTests/Query/PrimitiveCollectionsQueryCosmosTest.cs | Added SQL baselines for Cosmos DB provider using ARRAY_CONTAINS |
| test/EFCore.Cosmos.FunctionalTests/Query/NorthwindAggregateOperatorsQueryCosmosTest.cs | Updated baseline showing IReadOnlySet now properly uses ARRAY_CONTAINS instead of equality check |
roji
approved these changes
Jan 5, 2026
roji
reviewed
Jan 5, 2026
This was referenced Oct 19, 2026
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.
Fixes #37081.
Fixes #36262.