简体   繁体   English

在Cosmos DB中查询$ type字段

[英]Query for $type field in Cosmos DB

I have a model persisted in Cosmos DB where I have some types that inherits from others types. 我在Cosmos DB中保留了一个模型,其中有一些类型是从其他类型继承的。 Something like: 就像是:

    class ParentType {
        public string name;
    }

    class ChieldTypeOne : ParentType {
        public string propertyA;
    }

    class ChieldTypeTwo : ParentType {
        public string propertyB;
    }

    class ThirdType {
        public List<ParentType> Parents;
    }

When I tried to query for all ThirdType documents where Parent.propertyB = 'somevalue', with Linq, I discovered that I can't use TypeOf<> with Cosmos DB .NET Client. 当我尝试使用Linq查询Parent.propertyB ='somevalue'的所有ThirdType文档时,我发现无法在Cosmos DB .NET Client中使用TypeOf <>。 I've try use SQL, but I don't know how to query for fields started with $ in the name to query for $type fields, that is created by Json.NET to differentiate for types of documents. 我尝试使用SQL,但是我不知道如何查询名称中以$开头的字段以查询$ type字段,该字段由Json.NET创建以区分文档类型。

Some one has experienced this situation and found a solution? 有人经历过这种情况并找到了解决方案?

Thks, ks

Luiz 路易斯

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM