我如何提供JSON片段作为CosmosDB中SqlParameter的值

问题描述 投票:0回答:1

在Cosmos DB中,我可以使用Json片段作为查询的where子句的一部分,这样>

SELECT * FROM c WHERE c.path.to.propery={"where":{"value":{"is":true}}}

产生结果(当然有结果)

现在我想在使用SqlParamter s查询时使用相同的想法>

var stmt = new SqlQuerySpec
{
  QueryText = "SELECT * FROM c WHERE c.path.to.propery=@myjson",
  Parameters = new SqlParameterCollection()
  {
     new SqlParameter{ Name = "@myjson", Value = ??? } 
  }
};

任何想法都需要什么(如果有的话)而不是???才能在查询中包含json片段{"where":{"value":{"is":true}}}

在Cosmos DB中,我可以将Json片段用作查询的where子句的一部分,以便SELECT * FROM c WHERE c.path.to.propery = {“ where”:{“ value”:{“ is”:true }}}产生结果(当然如果有...

c# azure-cosmosdb-sqlapi
1个回答
0
投票

我发现了以宇宙DB StringToObject函数形式的解决方案,以便

var myjson =  @"{""where"":{""value"":{""is"":true}}}"
var stmt = new SqlQuerySpec
{
    QueryText = "SELECT * FROM c WHERE c.path.to.propery=StringToObject(@myjson)",
    Parameters = new SqlParameterCollection()
    {
        new SqlParameter{ Name = "@myjson", Value = myjson } 
    }
};
© www.soinside.com 2019 - 2024. All rights reserved.