c# ドライバーは、特定の型を渡して 1 つを見つけると、ネストされたクラスを自動的に逆シリアル化します。以下の例を mongo db で親切にテストしてください。
public ActionResult Index()
{
// MongoDatabase databse = MongoDatabase.Create("mongodb://localhost:27017/BeniSoftLabs");
MongoDatabase mongodb = DBConn.DBConn.getDBConn();
var menu = mongodb.GetCollection<Menu>("Menu").FindOne();
}
public class Node
{
public virtual string NodeTitle { get; set; }
public virtual string Link { get; set; }
public virtual string IconName { get; set; }
public virtual string ClassName { get; set; }
public virtual IList<Node> NodeList { get; set; }
}
public class Menu
{
public virtual ObjectId id { get; set; }
public virtual IList<Node> MenuList { get; set; }
public virtual IList<Node> RightMenuList { get; set; }
}
そしてデータモデルは
{
"_id" : ObjectId("50fecb7d60df893ad0e25138"),
"MenuList" : [
{
"NodeTitle" : "About Us",
"Link" : "/href.html",
"IconName" : "icon-home",
"ClassName" : "active",
"NodeList" : null
},
{
"NodeTitle" : "Our Solution",
"Link" : null,
"IconName" : "icon-briefcase",
"ClassName" : "dropdown",
"NodeList" : [
{
"NodeTitle" : "HTML5 Apps",
"Link" : "#/HTML5Apps",
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "CSS3 Apps",
"Link" : "#/CSS3Apps",
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "Single Page Apps",
"Link" : "#/SPAApps",
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "Smart Phone Apps",
"Link" : "#/SMartPhoneApps",
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : ".Net Enterprise Apps",
"Link" : "#/NETEnterprise",
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "Node.js Enterprise Apps",
"Link" : "#/NodeEnterprise",
"IconName" : null,
"ClassName" : null,
"NodeList" : null
}
]
},
{
"NodeTitle" : "Technologies",
"Link" : null,
"IconName" : "icon-briefcase",
"ClassName" : "dropdown",
"NodeList" : [
{
"NodeTitle" : "HTML5 & CSS3",
"Link" : null,
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "Angular.js",
"Link" : null,
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "Node.js",
"Link" : null,
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "Asp.net MVC",
"Link" : null,
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "MongoDB",
"Link" : null,
"IconName" : null,
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "My Sql",
"Link" : null,
"IconName" : null,
"ClassName" : null,
"NodeList" : null
}
]
},
{
"NodeTitle" : "Why Us",
"Link" : null,
"IconName" : "icon-fire",
"ClassName" : null,
"NodeList" : null
}
],
"RightMenuList" : [
{
"NodeTitle" : "Join Us",
"Link" : null,
"IconName" : "icon-eye-open",
"ClassName" : null,
"NodeList" : null
},
{
"NodeTitle" : "Contact Us",
"Link" : null,
"IconName" : "icon-user",
"ClassName" : null,
"NodeList" : null
}
]
}