Lazy Loading and Retrieving child entities RRS feed

  • Question

  • Hi,

    Recently I develop a n-Tier application using EF4 as data access. I have a problem with enabled LazyLoading in CSDL.

      When I run the application and retrieve an entity, the child list is loaded by EF4 but when I re-run the application and retreive a child and then write code like 'childEntity.theParent.Name', theParent not loaded so I got NullPointerException.

    Is LazyLoading unidirectional from parent to child? if it's bidirectional, how could I enable it to load theParent?


    Best Regard 

    Thursday, November 18, 2010 8:51 AM


  • Hi,

    In N-Tier applications you should disable lazy loading behavior since it has no meaning in such scenarios.
    If you want to deliver an entity graph through a service you should use eager loading (using the Include method) and load the child or the parent and then send them to the client. 

    The relation between child and parent in EF is bidirectional. 

    Gil Fink
    • Proposed as answer by liurong luo Tuesday, November 23, 2010 10:48 AM
    • Marked as answer by liurong luo Thursday, November 25, 2010 6:31 AM
    Thursday, November 18, 2010 9:53 AM