In some of the documentation examples, "virtual" keyword is used on scalar entity properties, for example:
<a class="postlink" href="http://aspnetzero.com/Documents/Developing-Step-By-Step#creating-person-entity">http://aspnetzero.com/Documents/Develop ... son-entity</a>
I'm aware of using virtual to lazy load related entities from another table, but not clear on why "virtual" is used with string properties in these examples? Thanks!
5 Answer(s)
-
0
it's a requirement for EF to be able to create poco proxies
<a class="postlink" href="http://stackoverflow.com/questions/5597760/what-effects-can-the-virtual-keyword-have-in-entity-framework-4-1-poco-code-fi">http://stackoverflow.com/questions/5597 ... co-code-fi</a>
-
0
Thanks. Perhaps then the question should be: when defining entity classes under ABP, is there a case where a member should not be marked as virtual?
-
0
Hi,
Actually, EF does not require virtual for primitive types (those are not lazy loadable). I used to do it because NHibernate requires :). Also, it will be possible for derived entities to override it.
-
0
Thanks. So you would say that if using EF, only use "virtual" on navigation properties and not for primitive types?
-
0
Yes.