

Now the whole process is nothing more than making round trips to the database for data if needed (of course in runtime). It’s also required to enable the proxy creation and lazy loading inside the DbContext object but it’s set by default. We can mark specific navigation properties or even whole entities as “lazy” by making them virtual.

The idea that stands behind is really simple. Using (var context = new BookStoreContext())īefore running the program let’s refresh our knowledge about lazy loading supported by Entity Framework. Public virtual DbSet Authors Īnd the program which will help us understanding the problem: Public BookStoreContext() : base("BookStore")ĭatabase.SetInitializer(new DropCreateDatabaseIfModelChanges()) Public class BookStoreContext : DbContext A week ago I was asked about using Includemethod while using Entity Framework? Is that related to lazy loading? Should we use it every time when working with IQueryable? If you’re not sure, just keep reading 😉īefore we move forward to the Include method, let me introduce a simple EF example with two entities (one-to-many relation) and their Database context. As you probably guess the best way is to simply… write a blog post! And today’s one is going to be exactly created for that purpose. Why? Because we could optimize that process and share our knowledge with other folks out there. He said that each of us has a limited number of keystrokes until we die so, it’s such a waste to write a dedicated email with long answer and examples in the code. While watching his “soft” talk titled “Scaling Yourself” I was surprised when he described his way of answering some questions coming from all over the world (via email). I’m a really big fan of Scott Hanselman and the way he manages his personal/work time.
