Base solution for your next web application
Open Closed

virtual property in Entity #3598


User avatar
0
fguo created

I noticed that most entity properties are defined as "public virtual ..." in Phonebook example and other code. As my understanding, "virtual" is for lazy loading or overwriting in derived classes. So, it is useful to define "virtual" on navigation properties (e.g. public virtual ICollection<Phone> Phones { get; set; }). What is the purpose to define all other entity properties as "virtual" (e.g. public virtual string Name { get; set; })? Does it effect performance on large DB tables?

Thanks,

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @fguo,

    It was required by NHibernate and we continued like this but you don't have to. It is not necessary for Entity Framework.

    Thanks.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)