I'm trying to use SQL query parameters with a WHERE ... IN
statement in an Azure Cosmos DB SQL API query:
var componentDesignGuids = new List<Guid>();
// ...
var queryDefinition = new QueryDefinition(
"SELECT componentDesign.guid, componentDesign.component.name, componentDesign.component.componentType " +
"FROM components componentDesign " +
"WHERE componentDesign.guid IN (@componentDesignGuids)")
.WithParameter("@componentDesignGuids", string.Join(",", componentDesignGuids.Select(guid => $"\"{guid}\""))));
but this results in a query where the replaced parameter is a single string, like IN ("guid0, guid1, guid2")
. Since this is an IN
clause, I want to put an indeterminate number of strings there, like IN ("\"guid0\", \"guid1\", \"guid2\"")
. I realize I can make this work with an interpolated string, but I want to be as safe with inputs as possible to prevent injection. How can I specify this with QueryDefinition
and/or WithParameter
?