【问题标题】:Query for $type field in Cosmos DB在 Cosmos DB 中查询 $type 字段
【发布时间】:2017-10-09 03:20:17
【问题描述】:

我在 Cosmos DB 中保留了一个模型,其中一些类型继承自其他类型。比如:

    class ParentType {
        public string name;
    }

    class ChieldTypeOne : ParentType {
        public string propertyA;
    }

    class ChieldTypeTwo : ParentType {
        public string propertyB;
    }

    class ThirdType {
        public List<ParentType> Parents;
    }

当我尝试使用 Linq 查询 Parent.propertyB = 'somevalue' 的所有 ThirdType 文档时,我发现我无法将 TypeOf 与 Cosmos DB .NET 客户端一起使用。我尝试使用 SQL,但我不知道如何查询名称中以 $ 开头的字段以查询 $type 字段,该字段由 Json.NET 创建以区分文档类型。

有人遇到过这种情况并找到解决办法?

谢谢,

路易斯

【问题讨论】:

    标签: c# linq azure-cosmosdb


    【解决方案1】:

    简单的答案是使用索引访问,例如:

    Select * From c Where c["$type"] = "TheType"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-24
      • 2018-12-17
      • 2018-07-20
      • 2021-12-14
      • 2019-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多