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

  • SEARCH
  • Home
  • 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 8296217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:54:20+00:00 2026-06-08T14:54:20+00:00

Please find the table structure below: Folderid parentFolderid Guid 1 0 1234 2 1

  • 0

Please find the table structure below:

Folderid                    parentFolderid              Guid
1                           0                           1234
2                           1                           5678
3                           2                           9012
4                           3                           87697
5                           7                           4443 

The requirement is if I pass folderId the function has to give me all the guids.

For example:If I pass 1 to the function, I should get first four Guids(parent and its children).
I have a function which returns all the guids as follows:

public List<Guid> Folders(int folderId)
{ 
    // To get the folderids based on parentfolderid
    var a = entity.Where(x => x.parentfolderId == folderId).FirstOrDefault();
     return a;

}

I am able to get only up to one level of ids.

Is there any way to get parent, its children, grandchildren till the leaf?

  • 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-06-08T14:54:22+00:00Added an answer on June 8, 2026 at 2:54 pm

    If you are able to get that table to a class, check this out:

    public class Entity
    {
        public int ID { get; set; }
        public int ParentID { get; set; }
        public string Name { get; set; }
    
        public static List<Entity> GetTree(int ID, List<Entity> ListToSearch, bool First = true)
        {
            List<Entity> FilteredEntities = new List<Entity>();
    
            FilteredEntities.AddRange(ListToSearch.Where<Entity>(x => x.ParentID == ID).ToList<Entity>());
    
            List<Entity> Temp = new List<Entity>();
            foreach (Entity current in FilteredEntities)
            {
                Temp.AddRange(GetTree(current.ID, ListToSearch, false));
            }
    
            FilteredEntities.AddRange(Temp);
    
            if (First)
            {
                FilteredEntities.Add(ListToSearch.Where<Entity>(x => x.ID == ID).Single<Entity>());
            }
    
            return FilteredEntities;
        }
    }
    

    Usage:

        List<Entity> filteredEntities = Entity.GetTree(1, entities);
        List<string> onlyTheNames = filteredEntities.Select<Entity, string>(x => x.Name).ToList<string>();
    

    Regards

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

Sidebar

Related Questions

Please find the below code <?xml version=1.0 encoding=utf-8?> <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml layout=absolute> <mx:Script> <![CDATA[ [Bindable]
I have one intresting requirement to achieve. could you please help? Please find the
Please see the below code: I am have a table row defined using asp.net
I have 2 entities Customer and address please find the code below, I have
Please forgive my ignorance, but I wasn't able to find an answer elsewhere. I
Please find the code at http://jsfiddle.net/wlogeshwaran/NGL8P/4/ Here i want to make the 'hi' ,
What is the maximum memory one application can use? Please find instrument screenshot with
I am using readDirSync to get the files from a Diretory. PLease find the
Could you please help me find out the time complexity of the Fleury' algorithm
ereg and eregi functions will be deleted from Php. Please help to find alternatives

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.