I have the table structure as below,
I need the result like :
Redbook
|______Wedding
|______Christian
|______Muslim
|______Hindu
|______Birthday
|______Baptism
Which means, parentID having 0 should be the root and who's id(here 1) as parentID are its children (ie., wedding,birthday,Baptism) and so on... I tried something like:
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;
}
But it does not accomplish my needs.Please help.