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 8095341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:05:43+00:00 2026-06-05T21:05:43+00:00

This is a entity and i want to list all the children node for

  • 0

This is a entity and i want to list all the children node for a given node in a generic function

    public static List<T> BuildTree<T>(List<T> list, T selectNode string keyPropName, string parentPropName, string levelPropName, int level = 0)
    {
        List<T> entity = new List<T>();

        foreach (T item in list)
        {


        }


        return entity;
    }

example of the entity structure

    protected long _coakey;
    protected long _parentkey;
    protected string _coacode;
    protected string _coacodeclient;
    protected string _coaname;
    protected int _coalevel;

    [DataMember]
    public long coakey
    {
        get { return _coakey; }
        set { _coakey = value; this.OnChnaged(); }
    }

    [DataMember]
    public long parentkey
    {
        get { return _parentkey; }
        set { _parentkey = value; this.OnChnaged(); }
    }

    [DataMember]
    public string coacode
    {
        get { return _coacode; }
        set { _coacode = value; this.OnChnaged(); }
    }

    [DataMember]
    public string coacodeclient
    {
        get { return _coacodeclient; }
        set { _coacodeclient = value; this.OnChnaged(); }
    }

    [DataMember]
    public string coaname
    {
        get { return _coaname; }
        set { _coaname = value; this.OnChnaged(); }
    }

    [DataMember]
    public int coalevel
    {
        get { return _coalevel; }
        set { _coalevel = value; this.OnChnaged(); }
    }
  • 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-05T21:05:45+00:00Added an answer on June 5, 2026 at 9:05 pm

    I have solved it my self hope it help you

        public static List<T> BuildTree<T>(List<T> list, T selectedNode, string keyPropName, string parentPropName, int endLevel = 0, int level = 0)
        {
            List<T> entity = new List<T>();
            Type type = typeof(T);
            PropertyInfo keyProp = type.GetProperty(keyPropName);
            string _selectedNodekey = keyProp.GetValue(selectedNode, null).ToString();
    
            PropertyInfo parentProp = type.GetProperty(parentPropName);
            foreach (T item in list)
            {
    
                string _key = keyProp.GetValue(item, null).ToString();
                string _parent = parentProp.GetValue(item, null).ToString();
    
                if (_selectedNodekey == _parent)
                {
                    T obj = (T)Activator.CreateInstance(typeof(T));
                    obj = item;
                    entity.Add(obj);
                    if (level == endLevel && level!=0) break;
                    entity.AddRange(BuildTree<T>(list, obj, keyPropName, parentPropName, level + 1));
                }
            }
    
    
            return entity;
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a list of parents and their children I want to return a list
I want add new Feed item on entity persist and update. I write this
I want to persist an Image in my Article Entity. Is this possible with
mI've this entity class: @Entity public class User implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) private
If I have this entity: @Entity class Pet { @Id long id; public enum
Let's say I have this entity (for Hibernate): @Entity public class Person { @Id
I have a Customer class defined like this: @Entity public class Customer { //...
I have a JPA object which has a many-to-many relationship like this: @Entity public
I have the following code: private Dictionary<int, Entity> m_allEntities; private Dictionary<Entity, List<IComponent>> m_entityComponents; public
i'll use some sample code to demonstrate my problem... this is an entity public

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.