Commit 1295048
authored
LINQ: Fixes Dictionary.Any() to generate OBJECTTOARRAY SQL (#5595)
The LINQ translator was generating invalid SQL for `Dictionary<string,
object>.Any()` queries. It treated dictionaries as standard enumerables
and used `JOIN` instead of Cosmos DB's required `OBJECTTOARRAY()`
function.
## Root Cause
`TypeSystem.IsEnumerable()` returns true for `Dictionary<K,V>` (via
`IEnumerable<KeyValuePair<K,V>>`), causing `ExpressionToSQL` to
translate dictionary access as a standard collection JOIN operation.
## Changes
- **TypeSystem.cs**: Added `IsDictionary()` check to identify dictionary
types
- **ExpressionToSQL.cs**: Wrap dictionary member access with
`OBJECTTOARRAY()` conversion
- **LinqDictionaryQueryTests.cs**: Added tests for dictionary query
translation
## Example
```csharp
// Query with Dictionary property
var query = container.GetItemLinqQueryable<MyDoc>()
.Where(d => d.AdditionalData.Any(kvp => kvp.Value == searchFor));
```
**Before (invalid SQL):**
```sql
SELECT * FROM c
WHERE EXISTS(SELECT VALUE x FROM x IN c.AdditionalData WHERE x.v = @Searchfor)
```
**After (correct SQL):**
```sql
SELECT * FROM c
WHERE EXISTS(SELECT VALUE x0 FROM x0 IN (SELECT VALUE ObjectToArray(c["AdditionalData"]))
WHERE x0["v"] = @Searchfor)
```
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/Azure/azure-cosmos-dotnet-v3/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>1 parent 3fc9ac3 commit 1295048
0 file changed
0 commit comments