简体   繁体   中英

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. 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. 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.

Some one has experienced this situation and found a solution?

Thks,

Luiz

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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