0

based on documentation, if you apply virtual keyword to navigation property, you Enable Lazy loading.

In another documentation, it says, to disable lazy loading you need to apply this code

context.Configuration.LazyLoadingEnabled = false;

Logically, why not just NOT apply virtual keyword in the first place?

I don't understand why over complicate things?

Thanks.

monstro
  • 6,254
  • 10
  • 65
  • 111
  • 1
    Excluding VIRTUAL turns lazy loading off for that item. `context.Configuration.LazyLoadingEnabled = false;` turns it off for the entire context. Not really that complicated: http://www.entityframeworktutorial.net/lazyloading-in-entity-framework.aspx – Steve Greene Aug 17 '18 at 21:04

1 Answers1

0

The reason the virtual keyword was applied to navigation properties was to limit the entire dependency tree from being loading when making a call into the database by default. Check out these other SO questions/answers.

Why Navigation Properties are virtual by default in EF

Why use 'virtual' for class properties in Entity Framework model definitions?

user1011627
  • 1,741
  • 1
  • 17
  • 25