Click here to Skip to main content
15,915,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I wanna create dynamic menu using Linq ,
I have three tables

1.Menu_master
menu_id|menu_name

2.SubmenuParent_master
Parent_Menu_id | Parent_menu_name| menu_id

3.Submenu_child_master
child_menu_id |child_menu_name| Parent_Menu_id
where all three tables connected with foreign key

C#
public object[] bindParentMenu(SubmenuParent_master obj)
{
    object[] parentmenu = (from p in db.Parent_masters
                                   select p).ToArray();
           return parentmenu;
}
public object[] bindchildMenu(chaild_master obj)
{
     object[] childmenu = (from p in db.chaild_masters
                    select p).ToArray();
     return childmenu;
}

please Guide me to write linq query for sub menu
thank you
Posted
v2
Comments
Sampath Lokuge 15-Mar-14 7:07am    
Can you explain the code snippet which you have provided ? That one for what ?

1 solution

first of all, do not use object[]s. generics should be your first choice when applicable.

If you use linq to sql, you can select values from DataContext [^] like :

var level0 = dataContext.Menu_masters.ToList();
var level1 = dataContext.SubmenuParent_masters.ToList();
var level2 = dataContext.Submenu_child_masters.ToList();


but there exists better. If you mean by "menu" as MainMenu[^],
then you can store all your menu items in one table with foreign key values. you can use this table to create your menu.
 
Share this answer
 

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