❔ What is the Best Way to convert the nested C# object to key value pair
I want to store the C# objects in MongoDB which can be dynamic nature in key value fashion
like Attributes: [ { "key": "Name", "value": "Bob"}, {"key": "ID", "value": "123"..]
my C# Class is like this
public class Employee{
public string Name {get; set;}
public string ID {get;set;}
public Department Departments {get; set;}
}
public class Department{
public string Name {get; set;}
public string Description {get; set;}
}
How can I represent the nexted C# object to key value json ?
Any thoughts/suggestions ?
5 Replies
Json.Serialize()
it
Ah, nevermind, you want to do some weird shit
You could probably use reflections
To turn your neat objects into this eldritch madnessya I thought of that but when i start to dig into nested Types like Employee.Department i am not sure how should i represent this for the key may be my key can be "Employee.Department" but i want to make it easy to reconstruct to C# Type and work with it as well
not sure what's the best way to do it so its easy to index in Mongo and also easy to read and convert back to C# object
Doesn't Mongo driver just let you do
_database.Orders.Add(person);
and what not?
Somehow I doubt you actually need to serialize everything manually to some demented JSON and save that in Mongo
I know non-relational databases are bad, but I don't think they are this garbageya this is not domain related Data, want to capture the event data coming from external sources, I agree I have to serialize it manually and do something
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.