2

It's possible to partially disable LazyLoading ? For example :

If we have : ParentObject - ChildLevel1- ChildLevel2

I want to disable LazyLoading only for ChildLevel1 , so when the ParentObject are loaded , the ChildLevel1 should not be loaded automatically. But when I manually will load ChildLevel1 , for childlevel2 the Lazyloading should function as usual.

It's this possible ?

Thank you !

alex
  • 694
  • 3
  • 15
  • 35

1 Answers1

1

Entity Framework requires your navigation properties to be marked as public virtual and not sealed to enable lazy loading. So, to achieve your escenario, just remove the virtual keyword from your ChildLevel1 navegation property in the ParentObject class.

I suggest you read this post. Another useful link describing this is MSDN's Requirements for Creating POCO Proxies

Community
  • 1
  • 1
ocuenca
  • 38,548
  • 11
  • 89
  • 102
  • But the problem is that I don't want this permanently. Only in some cases I want this scenario , in other cases I need LazyLoading to work as usual for ChildLevel1 too. – alex Feb 05 '15 at 23:35
  • Sorry, but I'm afraid that is not possible.If you define your navigation property virtual, EF will at runtime create a new class (dynamic proxy) derived from your ParentObject class and use it instead. This new dynamically created class contains logic to load navigation property when accessed for the first time. This is not something that you can enable or disable at runtime – ocuenca Feb 05 '15 at 23:44