-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ArrayContains to CosmosLinqExtensions to allow partial matching
The `Array_Contains` funtion 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 Linq `array.Contains(item)` extension methods. This adds this adds an explicit mapping to this function to allow it to be called in Linq like this: `documents.Where(document => document.ObjectArray.ArrayContains(new { Name = "abc" }, true))`
- Loading branch information
Ben Robinson
committed
Feb 3, 2025
1 parent
0958198
commit 8ec125f
Showing
7 changed files
with
200 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
94 changes: 94 additions & 0 deletions
94
...selineTest/TestBaseline/LinqTranslationBaselineTests.TestArrayContainsBuiltinFunction.xml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<Results> | ||
<Result> | ||
<Input> | ||
<Description><![CDATA[ArrayContains in Select clause with int value and match partial true]]></Description> | ||
<Expression><![CDATA[query.Select(doc => doc.ArrayField.ArrayContains(Convert(1, Object), True))]]></Expression> | ||
</Input> | ||
<Output> | ||
<SqlQuery><![CDATA[ | ||
SELECT VALUE ARRAY_CONTAINS(root["ArrayField"], 1, true) | ||
FROM root]]></SqlQuery> | ||
</Output> | ||
</Result> | ||
<Result> | ||
<Input> | ||
<Description><![CDATA[ArrayContains in Filter clause with int value and match partial true]]></Description> | ||
<Expression><![CDATA[query.Where(doc => doc.ArrayField.ArrayContains(Convert(1, Object), True))]]></Expression> | ||
</Input> | ||
<Output> | ||
<SqlQuery><![CDATA[ | ||
SELECT VALUE root | ||
FROM root | ||
WHERE ARRAY_CONTAINS(root["ArrayField"], 1, true)]]></SqlQuery> | ||
</Output> | ||
</Result> | ||
<Result> | ||
<Input> | ||
<Description><![CDATA[ArrayContains in Select clause with object value and match partial true]]></Description> | ||
<Expression><![CDATA[query.Select(doc => doc.ObjectArrayField.ArrayContains(new AnonymousType(Field = "abc"), True))]]></Expression> | ||
</Input> | ||
<Output> | ||
<SqlQuery><![CDATA[ | ||
SELECT VALUE ARRAY_CONTAINS(root["ObjectArrayField"], {"Field": "abc"}, true) | ||
FROM root]]></SqlQuery> | ||
</Output> | ||
</Result> | ||
<Result> | ||
<Input> | ||
<Description><![CDATA[ArrayContains in Filter clause with object value and match partial true]]></Description> | ||
<Expression><![CDATA[query.Where(doc => doc.ObjectArrayField.ArrayContains(new AnonymousType(Field = "abc"), True))]]></Expression> | ||
</Input> | ||
<Output> | ||
<SqlQuery><![CDATA[ | ||
SELECT VALUE root | ||
FROM root | ||
WHERE ARRAY_CONTAINS(root["ObjectArrayField"], {"Field": "abc"}, true)]]></SqlQuery> | ||
</Output> | ||
</Result> | ||
<Result> | ||
<Input> | ||
<Description><![CDATA[ArrayContains in Select clause with int value and match partial false]]></Description> | ||
<Expression><![CDATA[query.Select(doc => doc.ArrayField.ArrayContains(Convert(1, Object), False))]]></Expression> | ||
</Input> | ||
<Output> | ||
<SqlQuery><![CDATA[ | ||
SELECT VALUE ARRAY_CONTAINS(root["ArrayField"], 1, false) | ||
FROM root]]></SqlQuery> | ||
</Output> | ||
</Result> | ||
<Result> | ||
<Input> | ||
<Description><![CDATA[ArrayContains in Filter clause with int value and match partial false]]></Description> | ||
<Expression><![CDATA[query.Where(doc => doc.ArrayField.ArrayContains(Convert(1, Object), False))]]></Expression> | ||
</Input> | ||
<Output> | ||
<SqlQuery><![CDATA[ | ||
SELECT VALUE root | ||
FROM root | ||
WHERE ARRAY_CONTAINS(root["ArrayField"], 1, false)]]></SqlQuery> | ||
</Output> | ||
</Result> | ||
<Result> | ||
<Input> | ||
<Description><![CDATA[ArrayContains in Select clause with object value and match partial false]]></Description> | ||
<Expression><![CDATA[query.Select(doc => doc.ObjectArrayField.ArrayContains(new AnonymousType(Field = "abc"), False))]]></Expression> | ||
</Input> | ||
<Output> | ||
<SqlQuery><![CDATA[ | ||
SELECT VALUE ARRAY_CONTAINS(root["ObjectArrayField"], {"Field": "abc"}, false) | ||
FROM root]]></SqlQuery> | ||
</Output> | ||
</Result> | ||
<Result> | ||
<Input> | ||
<Description><![CDATA[ArrayContains in Filter clause with object value and match partial false]]></Description> | ||
<Expression><![CDATA[query.Where(doc => doc.ObjectArrayField.ArrayContains(new AnonymousType(Field = "abc"), False))]]></Expression> | ||
</Input> | ||
<Output> | ||
<SqlQuery><![CDATA[ | ||
SELECT VALUE root | ||
FROM root | ||
WHERE ARRAY_CONTAINS(root["ObjectArrayField"], {"Field": "abc"}, false)]]></SqlQuery> | ||
</Output> | ||
</Result> | ||
</Results> |
This file contains 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
This file contains 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
This file contains 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