Added ArrayContains to CosmosLinqExtensions to allow partial matching #4992
+198
−7
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.
Pull Request Template
Description
The
Array_Contains
function CosmosDB Sql has a 3rd parameter which allows it to do a partial match on the given item. This is unable to be called with the built in Linqarray.Contains(item)
extension methods.This adds this adds an explicit mapping to this function to allow it to be called in Linq like this:
Remarks
ArrayContains
name instead ofContains
I namef the new
CosmosLinqExtensions
extension methodArrayContains
instead ofContains
as the other extensions methods matched thier Cosmos Sql counterparts and because this is for a direct invokation of this function.Can change the name if you require.
ArrayContains
SignatureThe
itemToMatch
paramater is anobject
as it will need to take anonymous objects (and c# doesn't have a similar concept to typescript'sPartial<T>
). If was generic callers would be force to pass in an object of the same type, and the default serialiser creates object with every property that exists on the class. So the created query object with default values (e.g. Array_Contains(root["Items"],{ "I" = 0, "s" = null })
)which would the cause Cosmos to try and match on all properties.Because it's not generic the
obj
is thenIEnumerable
, so it would at a minimum only work on iterable values.As if this was
ArrayContains<T>(this IEnumerable<T> obj, T itemToMatch, bool partialMatch)
then we'd need to always pass the sameT
type to this method. The downside is you loose some type checking (the anonymous object could have a property name typed wrong),Modification to
ArrayContainsVisitor
The
ArrayContainsVisitor
visitor already exists for theContains
Linq mappings, the I modified this to work with the different extension version for Array Contains.Type of change
Closing issues
closes #4991
To automatically close an issue: closes #IssueNumber