Intensivist
Intensivist

Reputation: 1017

Is DBContext added automatically with EF 6 or must it be added manuall?

New to EF. Following along with DBContext by Lerman/Miller.

When I start a new project, adding EF6 (Database First), the DBContext seems to be added as a default (ie I don't have to add the DBContext separately with T4). Also, for Lazy Loading, the "virtual" needed in the class definitions also seems to be there by default (I don't have to add it like in the book). Is this what is expected?

Upvotes: 1

Views: 43

Answers (2)

Masoud
Masoud

Reputation: 8171

When you use Database First approach and use EF x DbContext Generator it creates the DbContext for you automatically and set the navigation properties, virtual. If you want to disable lazy loading you can simply use following code

public class MyContext : DbContext
{
   public MyContext()
   {
       this.Configuration.LazyLoadingEnabled = false;
   }
}

Upvotes: 1

Liviu Mandras
Liviu Mandras

Reputation: 6607

Most probably the books you are reading are for code first development. If you use database first(especially with the designer) you don't need to make changes.

Upvotes: 0

Related Questions