我正在使用以下查询来查询CosmosDB,由于ARRAY_CONTAINS,我无法使用LINQ。问题是我的应用程序崩溃,因为SQLParameter从未被替换,因此为null异常。
查询看起来像这样
var sqlStatement = new SqlQuerySpec
{
QueryText = "SELECT * FROM c where ARRAY_CONTAINS(c.locales[0].categories, @category)",
Parameters = new SqlParameterCollection()
{
new SqlParameter{ Name = "@category", Value = "Homeware" }
}
};
IDocumentQuery<JObject> query = client.CreateDocumentQuery<JObject>(
collectionUr
sqlStatement)
.AsDocumentQuery();
while (query.HasMoreResults)
{
items.AddRange(await query.ExecuteNextAsync<JObject>());
}
答案 0 :(得分:0)
您可以参考以下对我有用的代码:
var Parameters = new SqlParameterCollection()
{
new SqlParameter(Name = "@category", Value = "Homeware")
};
IQueryable<Pojo> queryable = client.CreateDocumentQuery<Pojo>(
uri,
new SqlQuerySpec
{
QueryText = "SELECT * FROM c where ARRAY_CONTAINS(c.locales[0].categories, " + Parameters[0].Value + ")"
});
答案 1 :(得分:0)