I have a custom form object structure I use successfully with mongodb.
I've been investigating the possibility of replacing Mongo with DocumentDb.
My Class structure consists of a base control that different types of control inherit from. e.g. Textbox control, Dropdown Control
In mongo I use the discriminator field to store the actual type, in the c# DocumentDb driver I cant see find the same feature.
below is a sample of how mongo stores my class structure.
{
"_t" : "TextboxControl",
"LabelText" : "Location of incident",
"IsRequired" : true,
"_id" : "cbe059d9-b6a9-4de2-b63b-14d44b022e37"
}
In documentdb the structure looks like
{
"LabelText": "Location of incident",
"IsRequired": true,
"id": "cbe059d9-b6a9-4de2-b63b-14d44b022e37"
}
As you can see the mongo version has a "_t" property stating the actual type, this is then used when I read the data to create the correct type. In the documentdb version it is simply a fieldtype
In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface. According to that definition, no, C doesn't natively support polymorphism.
Polymorphism is an effect of inheritance. It can only happen in classes that extend one another. It allows you to call methods of a class without knowing the exact type of the class. Also, polymorphism does happen at run time.
No it doesnt. C is not an Object Oriented language. Inheritance is a property of OO languages.
Explanation: Ada is the language which supports the concept of classes but doesn't support the polymorphism feature. It is an object-based programming language.
After many weeks of searching I eventually came across the answer
https://github.com/markrexwinkel/azure-docdb-linq-extension
Basically this library extends the DocumentDb's C# SDK and allows for custom JSON settings to be applied. Under the hood the documentdb driver users json.net.
I now get the property "$type" which is a feature built into newtonsoft's excellent json.net library.
My json now looks like
{
"$type" : "MyNameSpace.DropDownSingleFormBuilderControlTemplate, MyLibrary",
"LabelText" : "Label Text"
"IsRequired" : true,
"_id" : "cbe059d9-b6a9-4de2-b63b-14d44b022e37"
}
I think they added support for jsonserializer. You can add it via the
RequestOptions, TypeNameHandling.All
var s = new RequestOptions(){ JsonSerializerSettings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }}
var result = await Client.CreateDocumentAsync(CollectionUri, @event2, s);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With