locked
Loading an entire tree - EF Code First RRS feed

  • Question

  • Hello experts,

     

    I have a hierarchical tree-like entity defined below:

        public abstract class ViewNode
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public virtual ViewNode Parent { get; set; }
            public virtual ICollection<ViewNode> Children { get; set; }
        }
    
    

    I would like to create a method that returns the entire tree for a given ID like so:

        public ViewNode GetFullViewTree(int ViewNodeID)
        {
        }
    
    


    In other words, I would like the grandchildren and great-grandchildren and so on included in the returned result. How can I do this?

     

    Thanks,

    ~fakepoo

    Monday, October 3, 2011 7:33 PM

Answers

  • Hi fakepoo;

    Look at this artical Loading Related Objects and the section Defining a Query Path to Shape Query Results

     

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, October 3, 2011 8:14 PM
  • Hi

    If you are looking for Turning off lazy loading for particular navigational property, simple you change your method to non-virtual.

    or

    on context level, you can set Configuration.LazyLoadingEnabled = false;

     

    If you are looking for only certain scenario, see the link provided by Fernandoo...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    Tuesday, October 4, 2011 3:10 AM

All replies

  • Hi fakepoo;

    Look at this artical Loading Related Objects and the section Defining a Query Path to Shape Query Results

     

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, October 3, 2011 8:14 PM
  • Hi

    If you are looking for Turning off lazy loading for particular navigational property, simple you change your method to non-virtual.

    or

    on context level, you can set Configuration.LazyLoadingEnabled = false;

     

    If you are looking for only certain scenario, see the link provided by Fernandoo...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    Tuesday, October 4, 2011 3:10 AM