Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Virtual Properties

What is the effect of not marking navigation properties virtual for Entity Framework (v4) entities?

If I don't use lazy loading, but neglect to properly eager load, what will happen upon accessing the (not loaded) property?

Would there be any other impact outside of lazy loading, or is that the main feature that requires virtual navigation properties?

like image 243
Phil Sandler Avatar asked Feb 09 '13 03:02

Phil Sandler


1 Answers

There are two effects. One is on lazy loading, which just won't work if the property is not virtual. But lazy loading isn't always something you want.

The second is change detection. If you're using pure POCOs or are using proxies but don't make the properties virtual, then change detection becomes more involved.

You can learn more about change detection here.

like image 129
Craig Stuntz Avatar answered Oct 14 '22 00:10

Craig Stuntz