it will be some thing like that
var fathers = GetParents().ToList();
getParents to get all the records that have 0 in it's parent Id. then
foreach (var f in fathers)
{
_cachedFathers.Add(f);
MyChilds(f);
}
private void MyChilds(Company comp)
{
tvi.Children = new ObservableCollection<JobDto>();
var childs = GetParents(tvi.CompanyId).ToList();
foreach (var c in childs)
{
comp.Children.Add(c);
}
}
GetParents(int companyId) shold give you all the companies that have "companyId" in the ParentId column
and in the Company Calsss you should have
public Company Parent { get; set; }
private ObservableCollection<Company> _children = new ObservableCollection<Company>();
public ObservableCollection<Company> Children
{
get { return _children; }
set { _children = value; OnPropertyChanged("Children"); }
}
that will give you an object fathers full of hierarchy data
Hope this help