Repository navigation
fix(filter): treat every IEnumerable<T> property as a collection - #203
Merged
Merged
Conversation
A filter on a collection property failed for IReadOnlyList<T>, IReadOnlyCollection<T>, HashSet<T>, arrays, and classes that inherit from List<T>. The == operator and the other comparison operators failed on a direct collection property of every type. - Detect a collection and its element type from IEnumerable<T> with one pair of helpers in Extensions.cs. - A comparison on a direct collection property matches when any element matches, the same as a nested path. - == null and != null on a collection property check the property for null. A nested path keeps the element comparison. - != on a collection emits !(z == value), because EF Core 10 with Npgsql can not translate z != value on a primitive collection. Fixes #201
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 #201
Problem
A filter on a collection property failed for some collection types:
^$and!^$failed onIReadOnlyList<T>,IReadOnlyCollection<T>,HashSet<T>, arrays, and classes that inherit fromList<T>.==and the other comparison operators failed on a direct collection property of every type,List<T>included. Only a nested path such asIngredients.Name == "salt"worked.Change
IsCollection()andGetCollectionElementType()inQueryKit/Extensions.csreadIEnumerable<T>from the interfaces of the type. They replace two copies of the check inFilterParserandPropertyResolver, and the checks in each operator.%makes it match when all elements match. This is the same as a nested path.Tags == nullandTags != nullcheck the property for null.Ingredients.Name == nullkeeps its old meaning: any element is null.!=on a collection emitsAny(z => !(z == value)). EF Core 10 with Npgsql can not translateAny(z => z != value)on a primitive collection. Both forms give the same SQL:t.value <> 'dinner'.Behavior change: the expression text for
!=and!=*on a nested path changed fromz != "flour"toNot((z == "flour")). The results do not change.Tests
QueryKit.UnitTests/CollectionTypeFilterTests.cs: 8 collection types, each with the same operators. Also number collections, null checks, and nested paths. Before the fix, 89 cases failed.QueryKit.IntegrationTests/Tests/CollectionTypeFilterTests.cs: a projection from an EF entity to a DTO withIReadOnlyList<string>andIReadOnlyCollection<string>, filtered on Postgres. This test found the!=translation fault.string[] Labelscolumn (text[]). Ten filters onTagsand onLabelsgave the same rows in memory and on Postgres.Out of scope
^^(in) on a collection property: Support the in operator (^^) on a collection property #202.