我有如下表结构,
我需要结果如:
Redbook
|______Wedding
|______Christian
|______Muslim
|______Hindu
|______Birthday
|______Baptism
这意味着,拥有0的parentID应该是root,并且who的id(此处为1)作为parentID是其子项(即婚礼,生日,洗礼)等等... 我试过像:
public List<specdetails> getProductDet(int ID)
{
List<specdetails> result;
using (APM context = new APM())
{
var res = (from s in context.M_CategoryDetails where s.CategoryID == ID select s).ToList();
result = res
.GroupBy(u=>u.ParentID)
.Select(grp => new specdetails
{
parentID = (int)grp.Key,
//ImageList = grp.ToList()
description = grp.FirstOrDefault().Description,
ID = grp.FirstOrDefault().ID,
catID = (int)grp.FirstOrDefault().CategoryID,
vPath = grp.FirstOrDefault().VirtualPath
}
).ToList();
}
return null; //result;
}
但它无法满足我的需求。请帮助。