Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a table:
userId LeftChild RightChild
1006 1007 1008
1007 1009 1011
1008 1014 1012
1009 1013 0
1011 0 0
1012 0 0
1013 1015 0
1014 0 0
1015 0 0
in which how to calculate the child node of userId=1006
plz Some one One Help me
Posted
Updated 6-Apr-14 18:17pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Apr-14 0:29am    
What have you tried so far?
—SA

1 solution

C#
GetChildForIDs(List<int> IDs)
{
   List<int> IdsToReturn = new List<int>();
   List<int> LIds = TableRepository.GetAll().where(x=>IDs.Contains(x.ID) & x.ID > 0).select(x=>x.LeftChild).ToList();
   List<int> RIds = TableRepository.GetAll().where(x=>IDs.Contains(x.ID) & x.ID > 0).select(x=>x.RightChild).ToList();
   
   IdsToReturn.AddRange(LIds);
   IdsToReturn.AddRange(RIds); 
   
   if(IdsToReturn.Count()>0)
   {
      GetChildForIDs(IdsToReturn);
      
      //Here Count is Class Level Static Variable
      Count = Count + IdsToReturn.Count();

   }
 
}


Now After Calling this method print Count Variable.You will get the count.
 
Share this answer
 
v3
Comments
NABIN SEN 7-Apr-14 5:10am    
what is TableRepository?
Pratik Bhuva 7-Apr-14 9:53am    
From where you are getting your data from dataBase.
you can imagine "TableRepository.GetAll()" as "List<yourtableobject> lstAllData".

in short your list that contain all data which you have shown in your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900