I know that navigation properties in Entity Framework must have the virtual keyword in front of them or else EF can't do it's navigation property magic. But what effect does putting the virtual keyword in front of other properties have? I saw an example recently wherein every single property on the entity was declared with the virtual keyword. Does EF 5 really lazy load every property if I do that or am I missing something about how that works?
Using virtual keyword for navigation properties is necessary for lazy loading. Using virtual keyword on all mapped properties is necessary for dynamic change tracking. All requirements both options are described in documentation.
In EF 4.0 dynamic change tracking was recommended approach and because of that POCO T4 Generator used virtual properties but since EF 4.1 snapshot change tracking is recommended as initial option with shift to dynamic change tracking only when shapshot change tracking is victim of performance issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With