469,361 Members | 2,447 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,361 developers. It's quick & easy.

How can i write query record in table have parentID with condition parentID == 0 and

Hi Everyone,

Here i my LINQ query to get record in Table Menu with condition are parentID == 0(get root menu) and ID != (parentID list) (which is parent ID list is are id of menu record that have child), i just want to load all record includes root menu that have no children record and children record :

Expand|Select|Wrap|Line Numbers
  1. List<Menu> menus = MenuDAO.Instance.GetAll(); // Get All Record in Menu Table
  2. var parentID = (from p in menus where p.ParentID != 0 select new {p.ParentID}).Distinct(); // Get unique ParentID in Menu Table
  3.         List<int> numParentID = new List<int>();
  4.         foreach (var a in parentID)
  5.         {
  6.             numParentID.Add(a.ParentID);
  7.         } // assign to a list <int>
  8.         this.ddlMenu.DataSource = from m1 in menus
  9.                                   where !(numParentID).Contains((int)m1.ID) && m1.ParentID == 0
  10.                                   select new { m1.ID, m1.Name };
  11.         this.ddlMenu.Databind();
  12.  
And i run this code , i display record that have no children, do not display chilren record. Somebody help me fix it. My new in LINQ , thanks a lot.
Mar 30 '11 #1
0 998

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Hans | last post: by
4 posts views Thread by John | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.