C
C#9mo ago
ashokp

❔ 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
Angius
Angius9mo ago
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 madness
ashokp
ashokp9mo ago
ya 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
Angius
Angius9mo ago
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 garbage
ashokp
ashokp9mo ago
ya 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
Accord
Accord9mo ago
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.
Want results from more Discord servers?
Add your server
More Posts
❔ Blazor WebAsm (.NET6) Breakpoints No Longer WorkingI had them working a few months ago before I took a break from the project but now they simply don't❔ Representing a custom map using GeoJSON data instead of a map of the globe. Is it possible?I was wondering if it were possible to create a custom map not of the Earth and use GeoJSON to creat❔ RecyclableMemoryStreams and Sending a Byte ArrayI am utilizing `RecyclableMemoryStream` to pool my memory streams in my networking project, but the ❔ What is the purpose of `ModelBindingContext.Model`, `ModelName`, and `ModelBinderAttribute.Name`?The docs are very unclear about this. If I should set `ModelBindingContext.Result` to `ModelBindingR❔ System.Numerics.Vector<double> limited to 2 components with NativeAOT instead of 4Hi! Im using the mentioned Vector struct for double Vectors and have seen that using NativeAOT it on❔ SSH.Net library using in C# App questionHello all, it is no problem to connect to an ssh server and run commands and copy files to the remot❔ how do i use discord webhooks in a console app?title❔ MSSQL server is not connecting to server please help me.TITLE: Connect to Server ------------------------------ Cannot connect to DESKTOP-C2CJAPC. -------❔ 100 Day Coding ChallengeSo for something called the gold dofe I need to a skills section for 18 months which can essentially❔ OpenIddict Tokens' Availability Depends On Request's OriginI'm using ASP.NET Core with OpenIddict authentication as the backend of my website. On the frontend,