Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:58:55+00:00 2026-05-27T22:58:55+00:00

I have a table named Drinking. Here is how it looks: Name idCategory idParentCategory

  • 0

I have a table named Drinking.

Here is how it looks:

Name         idCategory  idParentCategory
drink            1              1
alcohol          2              1
nonalcohol       3              1
tea              5              3
juice            4              3
sparkling        6              4
nonsparkling     7              4
pepsi            8              6
schweppes        9              6
wine            10              2
beer            11              2

Now, the input is idCategory. As you can see there isn’t property idChildren. What I am trying to do is find the ids of the children.

For example, if the input is 1, the output should be 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11.

Here is what I tried:

public void myMethod()
{
    List<Drinking> drinkingList= (from d in myEntities.Drinking
                              select d).ToList();
    foreach (var d in drinkingList)
    {
       if (d.Drinking2Reference.EntityKey != null)
       {
          s = c.Drinking2Reference.EntityKey.EntityKeyValues[0].Value.ToString();
          idPD = Int32.Parse(s);
          //get idParent
          if (idPC == idCat)
          {
             //if idParent is equal as the input, put this idCategory
             //in a list of integers.
             //Now, here comes the tricky part.
             //I should continue with this loop AND repeat this for
             //every child of idPC.
             //Where to put the call for this method?
             //Where to put the return statement?
             //Here is what I'm doing
             myMethod(idPC);
          }
          else
          {
             myMethod(idPC);
          }
       }

            }
}

My goal is to fill a list with the ids of the children and greatchildren

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:58:55+00:00Added an answer on May 27, 2026 at 10:58 pm
    public void myMethod(int value)
    {
        List<int> intList = new List<int>();
        List<Drinking> drinkingList= (from d in myEntities.Drinking
                              select d).ToList();
        foreach (var d in drinkingList)
        {
           if (d.Drinking2Reference.EntityKey != null)
           {
              if(d.idCategory == value)
                 intList.Add(value);
              else {
                 for(int i=0; i < intList.Count; i++) {
                    if(intList.ElementAt(i) == d.idParentCategory)
                       intList.Add(d.idCategory);
                 }
              }
    
           }
        }
        //Print numbers    
    }
    

    I haven’t tested this, but I feel like it should work. Feel free to comment if you catch something. Also, the table has to be sorted by idParentCategory for this to work. I will also say that with this situation I would recommend you look into using trees rather than a table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named categories, which contains ID(long), Name(varchar(50)), parentID(long), and shownByDefault(boolean) columns.
I have a table named visiting that looks like this: id | visitor_id |
I have a database table (named Topics) which includes these fields : topicId name
I have a table named item with two attributes ( code and name ).
i have a table named item with four attribute name,code,class,value now i want to
I have a table named master with columns id , name , surname ,
I have table named x Here is the sample data in table x Column1_
I have one table named Staff in access and also have this table(same name)
I have a table named foobar with columns name and location . I want
I have a table named tbl_course nad the data is like SID name DisplayOrder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.