I am working through a tutorial ‘Professional ASP.NET MVC 3’ by J Galloway. In this tutorial, Jon shows us how to build the MVC music store.
I am at the part where we are creating CS classes to model the data using EF code first.
I all the examples in the book, public virtual int property {get; set; } is used with no explanation. The term virtual is stuffed EVERYWHERE.
Elsewhere on the web, I have not seen the term virtual used with any kind of concistency whatsoever.
Could anybody explain to me:
- The purpose of the term ‘virtual’ in this particular context
- Is using ‘virtual’ necessary?
- Why do some people use ‘virtual’ and others do not?
- Why do some people only use ‘virtual’ when defining foreign keys?
- What is the best practice use of the term ‘virtual’?
Many thanks in advance
In order to truly understand the
virtualkeyword you are going to want to read up on Polymorphism in general:Once you understand these concepts better you might be able to determine whether or not the method you are creating from the book needs to be
virtualor not.