In some MVC Examples(Code First Approach), during defining the class for Databace, I found the statement like as
"Public Virtual <classname> Identifier{get;set;}", or "Public Virtual ICollection<classname> Identifier{get;set;}".
Can any one tell me the exact use of using such kind of statements with Virtual Keyword..
Declaring a property or method as virtual means that derived classes can override that property or method. This is particularly useful when using a proxy pattern which some ORMs use in implementing lazy loading (for example, nHibernate). As such, when using
such technologies, it becomes necessary to mark those properties as virtual. [In c# things are not virtual unless explicitly mentioned, unlike in Java]
"If I can see further than anyone else, it is only because I am standing on the shoulders of giants."blog: www.heartysoft.com twitter: @ashic
Marked as answer by HeartattacK on May 05, 2012 10:33 AM
pavankumarmc...
Member
7 Points
97 Posts
Use of Virtual Keyword in defining the Class
May 05, 2012 09:33 AM|LINK
Hi all,
In some MVC Examples(Code First Approach), during defining the class for Databace, I found the statement like as
"Public Virtual <classname> Identifier{get;set;}", or "Public Virtual ICollection<classname> Identifier{get;set;}".
Can any one tell me the exact use of using such kind of statements with Virtual Keyword..
Example:http://gentlelogic.blogspot.in/2012/03/entity-framework-code-first-first.html
Thanks in advance...
mm10
Contributor
6445 Points
1187 Posts
Re: Use of Virtual Keyword in defining the Class
May 05, 2012 09:40 AM|LINK
If a method is declared virtual in a base class, classes that inherits from this base class can override the method.
HeartattacK
All-Star
55262 Points
5917 Posts
Moderator
MVP
Re: Use of Virtual Keyword in defining the Class
May 05, 2012 09:42 AM|LINK
Declaring a property or method as virtual means that derived classes can override that property or method. This is particularly useful when using a proxy pattern which some ORMs use in implementing lazy loading (for example, nHibernate). As such, when using such technologies, it becomes necessary to mark those properties as virtual. [In c# things are not virtual unless explicitly mentioned, unlike in Java]
blog: www.heartysoft.com
twitter: @ashic
pavankumarmc...
Member
7 Points
97 Posts
Re: Use of Virtual Keyword in defining the Class
May 05, 2012 10:29 AM|LINK
Yes I got your point....
Thanks...