首页 > 解决方案 > 参数化查询 - 可以使用 GeoJson 对象值吗?

问题描述

考虑以下:

给定以下文档结构:

// Document using Microsoft.Azure.Cosmos.Spatial.Point ...

public class test_doc
{

  public String id { get; set; }

  public Microsoft.Azure.Cosmos.Spatial.Point geopoint { get; set; }

  // More properties
  public String desc { get; set; }

}

构建不带参数的查询...

bounds_str = "{'type':'Polygon','coordinates':[[[-113.247049,53.657421],[-113.733431,53.657421],[-113.733431,53.393183],[-113.247049,53.393183],[-113.247049,53.657421]]]}";

sql_query_text = "SELECT * FROM testcontainer t WHERE ST_WITHIN( t.geopoint, " + bounds_str + ")";

query_def = new Microsoft.Azure.Cosmos.QueryDefinition( sql_query_text );

执行上述查询时,查询按预期工作:

Query Total time: 00:00:00.0067482
Total Request Units consumed: 6.73
Documents found: 2

现在使用参数构建 SAME 查询...

sql_query_text = "SELECT * FROM testcontainer t WHERE ST_WITHIN( t.geopoint, @bounds )";

query_def = new Microsoft.Azure.Cosmos.QueryDefinition( sql_query_text );

query_def.WithParameter( "@bounds", bounds_str );

执行上述查询时,我们会得到不同的(不正确的)结果...

Query Total time: 00:00:00.0054688
Total Request Units consumed: 3.1
Documents found: 0

标签: azure-cosmosdbspatial-query

解决方案


推荐阅读