I am trying to get data from db table called
Departments
Id
Name
ParentId
I want to create hierachical view in a dropdownlist to choose between departments
I want to retrieve the data with linq and bind it to the dropdownlist
any help ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
http://www.scip.be/index.php?Page=ArticlesNET18
worked for me
nice article
GetEmployeesHierarchy() method
I first started creating a new EmployeeHierarchy class. This class contains an Employee entity (the boss) and a collection of child employees.
In .NET 3.5 we have LINQ at our’s disposal. So I created a recursive GetEmployeesHierachy function which will start with the director (who does not have to report to anyone, ReportsTo = null) and query all employees which are working for him (ReportsTo == EmployeeId of boss). This will be repeated recursively. Finally this function will return a collection of EmployeeHierarchy objects.
This function can be called after a LINQ to SQL or LINQ to Entities (Entity Framework) query. Make sure to call the ToList() extension method. It is much more performant to first load all data from the database and then convert it to a hierachical structure. By calling the ToList() method all references to the database will be removed.