1
votes

I want to use Parameterized Queries with a Document Field as well as with the value at a specified Field for Cosmos DB. https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-sql-query#parameterized-queries

For example:

SELECT *
FROM Families f
WHERE @field = @value 

I want to be able to specify something like f.lastName for @field, and Smith for @value.

Is this not possible? Trying to do this over the .NET SDK, it doesn't seem to work, no matter what I do.

2

2 Answers

1
votes

I found a way to do this.

You can use the Quoted Property Accessor

Here is how you'd do it:

SELECT *
FROM Families f
WHERE f[@field] = @value 
0
votes

Based on the examples in the link, @field = @value is not supported.

SELECT *
    FROM Families f
    WHERE f.lastName = @lastName AND f.address.state = @addressState

If your filter column is flexible, you could splicing query sql as String by yourself.

'SELECT *
FROM Families f
WHERE ' + filterColumn + ' = @value'