alex
alex

Reputation: 720

Entity Framework : Partially disable LazyLoading

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 !

Upvotes: 2

Views: 55

Answers (1)

ocuenca
ocuenca

Reputation: 39326

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

Upvotes: 1

Related Questions