Results 1 to 4 of 4

Thread: Get all parent/childs

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Get all parent/childs

    I am trying to get all the parents and its children objects from an object. I need to basically keep travelling through it from a single object i have. so..


    object has:
    =====
    entities


    I need to go through the object's entities, and its entities etc.... until it gets to the root entity of the object, then work its way downwards because I need to check for uniqueness of an entity

    how can I do this using recursion?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Get all parent/childs

    You use GetType to get an object's type. You use GetProperties to get a type's properties. You use GetValue to get a property's value. And so on, and so on, and so on...
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Get all parent/childs

    sorry. my question was not that clear

    basically I want to go through each and every single parent/children from the given object

    how can i get to the "root" parent from a child entity?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Get all parent/childs

    Quote Originally Posted by Techno
    how can i get to the "root" parent from a child entity?
    You wouldn't, unless the "child" has some property that refers to the "parent". For instance, consider this:
    CSharp Code:
    1. public class Class1
    2. {
    3.     private Class2 someField;
    4.  
    5.     public Class2 SomeProperty
    6.     {
    7.         get
    8.         {
    9.             return someField;
    10.         }
    11.         set
    12.         {
    13.             someField = value;
    14.         }
    15.     }
    16.  
    17. }
    18.  
    19. public class Class2
    20. {
    21.     //...
    22. }
    CSharp Code:
    1. Class1 c1 = new Class1();
    2. Class2 c2 = new Class2();
    3.  
    4. c1.SomeProperty = c2;
    Now, the Class2 object has no reference to the Class1 object. It has no idea the Class1 object even exists. How could you possibly get to c1 from c2?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width