this is my first question and sorry about my weak language.
I've got a table like this model;
public class Menu
{
[Key]
public int ID {get;set;}
public int ParentID {get;set;}
public string MenuName {get;set;}
public int OrderNo {get;set;}
public bool isDisplayInMenu {get;set;} // Menu or just for Access Authority
}
and there are many rows about menu like this;
ID ParentID MenuName Order
--- --------- ------------- ------
1 0 Main.1 1 >> if ParentID==0 is Root
2 1 Sub.1.1 1
3 2 Sub.1.2 2
4 0 Main.2 2
5 4 Sub.2.1 1
6 4 Sub.2.2 2
I have got a second class to prepare menu tree;
public class MyMenu:Menu
{
public List<MyMenu> Childs { get;set;}
}
I need a linq query to get the result like this;
var result = (...linq..).ToList<MyMenu>();
I am using a recursive function to get childs but this take too much time for to get results.
How can I write a sentence to get all menu tree in one query?
UPDATE:
I want to store main menu in a table. And this table will use on access authority control for users. Some rows will display inside the menu, some ones will use only to get access authority.
In this situation, I need many times to get the table tree. The table tree will be created as the filtered user authorities. When get the tree, stored in session. but many sessions means much RAM. If is there any fast way to get menu tree from the sql when I need then I will not store in the session.
See Question&Answers more detail:os