I know this may be a simple thing, but I am trying to loop through a list of groups. If the group has a subgroup I want it to repeat again for all subgroups
group1<br>
subgroup1<br>
Device1<br>
Device2<br>
group2<br>
subgroup1<br>
subsubgroup1<br>
Device3<br>
subgroup2<br>
Device4<br>
groups can be nested
In my class, I have added a List<GroupDevice> subgroup {get; set;}
in my code,
public void getgrouptree()
{
List<DeviceGroup> rootgroup = db.DeviceGroups
.Where(a => a.ParentGroupID == 0)
.ToList();
foreach (var item in rootgroup)
{
int count = db.DeviceGroups
.Where(a => a.ParentGroupID == item.GroupID)
.Count();
if (count >= 1)
{
item.SubGroup = db.DeviceGroups
.Where(a => a.ParentGroupID == item.GroupID)
.ToList();
}
}
return;
}
But I can only go one level down. How do I repeat this method for each subgroup etc...?