Let's say I have some data as you see below:
{
"Menu": {
"aaa": "aaa",
"bbb": {
"ccc": "ccc",
"ddd": "ddd"
},
"eee": "eee"
}
}
I can save this type of hierarchical data to database in a relational way like that:
https://i.stack.imgur.com/lmuq1.jpg
Sample list:
List<MenuItem> menuItems = new List<MenuItem>();
menuItems.Add(new MenuItem() { SiteMenuId = 1, ParentId = null, MenuName = "Menu", Url = null, SiteId = 1 });
menuItems.Add(new MenuItem() { SiteMenuId = 2, ParentId = 1, MenuName = "aaa", Url = "aaa", SiteId = 1 });
menuItems.Add(new MenuItem() { SiteMenuId = 3, ParentId = 1, MenuName = "bbb", Url = null, SiteId = 1 });
menuItems.Add(new MenuItem() { SiteMenuId = 4, ParentId = 3, MenuName = "ccc", Url = "ccc", SiteId = 1 });
menuItems.Add(new MenuItem() { SiteMenuId = 5, ParentId = 3, MenuName = "ddd", Url = "ddd", SiteId = 1 });
menuItems.Add(new MenuItem() { SiteMenuId = 6, ParentId = 1, MenuName = "eee", Url = "eee", SiteId = 1 });
So when I get the relational data from db as a List of MenuItem objects, how can I tranlate it back to json?
public partial class MenuItem
{
public int SiteMenuId { get; set; }
public int SiteId { get; set; }
public string MenuName { get; set; }
public string Url { get; set; }
public Nullable<int> ParentId { get; set; }
public int CreatedUser { get; set; }
public System.DateTime CreatedDate { get; set; }
public Nullable<int> ModifiedUser { get; set; }
public Nullable<System.DateTime> ModifiedDate { get; set; }
}
Do I have to use Dictionary or ExpandoObject or something? I want to have the the exact same format as I have at the begining.