In my project i want to add inheritance for some classes and save the generated objects to a documentcollection in the Cosmos DB database. To save the information about the type i use this preference in JSON.net: https://www.newtonsoft.com/json/help/html/SerializeTypeNameHandling.htm
But how can i query the collection by type without retriving all documents with LINQ in a typesafe way. The best would be to add a property to those classes named for example Type
which contains the information of the "$type" property of the JSON Object. Then i can query something like this:
return Client.CreateDocumentQuery<TEntity>(DocumentCollectionUri).Where(entity => entity.Type == typeof(Car).ToString());
This LINQ Query would be translated to SQL and then sent to the server. I only get back those objects of type car. This would be the optimum, is something like this possible and fast?