Why are members of a domain object (POCO) defined as virtual?

In the multiple zoom video, http://www.asp.net/mvc . The model object element was changed to virtual in the middle of the video. He did not give a detailed description of the change. Can someone clarify the need?

public class Restaurant
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual Address Address { get; set; }
    public virtual ICollection<Review> Reviews { get; set; }
}

By the way, is there IDBContexta repository template in the video? Should the code use a repository template for best practice if not?

public interface IDbContext
{
    IQueryable<Restaurant> Restaurants { get; }
    IQueryable<Review> Reviews { get; }
    int SaveChanges();
    T Attach<T>(T entity) where T : class;
    T Add<T>(T entity) where T : class;
    T Delete<T>(T entity) where T : class;
}

Update: It must be a number of repository templates. Typically, a repository template creates one class for one model object IRepository<T>. This object puts the entire object model into a single interface Restaurants, Reviews. How does this compare to a typical one?

+5
3

, POCO EF, , (POCOs). , , , EF . .

POCO POCO

+8

Entity Framework , .

+2

From msdn article ; "For change tracking proxies:

Each property that maps to an entity type property in the data model must have unsealed (NotOverridable in Visual Basic), public, and virtual (Overridable in Visual Basic) to receive and install accessors. "

+1
source

All Articles