1

I' m building ASP.NET Web API and using MongoDB to store data.

Some of properties should be dynamic at the class as below

public class SampleModel
{
    public dynamic Config { get; set; }
    public string Name {get; set; }
}

JObject is also used instead of dynamic.

This object couldn' t be inserted properly.

enter image description here

After that I tried to use BSonDocument property instead of dynamic/JOject. It' s working but I have to use the class with Jobject while deserializing data at controller and copied properties one by one to another class with BSonDocument.

I don' t want to copy properties etc. I need more dynamic structure. There should be proper way to do it but I couldn' t find.

Anil Kocabiyik
  • 1,178
  • 6
  • 17
  • 47

1 Answers1

0

I was using Newtonsoft JsonConvert.DeserializeObject method to deserialize input parameter at the controller.

Deserialized object was inspected at debug mode and it seems Ok.

After that deserialized object was inserted to MongoDb and it seems corrupted as above.

To solve it, custom serializer is created, SerializerBase class Serialize and Deserialize methods are overrided.

Maybe there are another solutions but I solve with this way.

Anil Kocabiyik
  • 1,178
  • 6
  • 17
  • 47
  • Can you provide some code examples of what was done? I've tried this solution but wasn't able to figure it out. – Urasquirrel Apr 13 '21 at 20:39