O'Reilly logo

Code-First Development with Entity Framework by Sergey Barskiy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Querying data in a database

In this section, we are going to look at our data using the query capabilities of Entity Framework. Typically, we will use LINQ to do this. We are going to start with a simple example though, accessing the data directly through DbSet. We will take a deeper look at LINQ in subsequent chapters. The code is quite simple and is as follows:

using (var context = new Context())
{
    var savedPeople = context.People;
}

If you set a breakpoint on the line with the last curly brace and look at the savedPeople variable in the Watch window, you will see one peculiar thing, something called Results View, shown in the following screenshot:

This illustrates an important concept. Entity Framework is using delayed query execution. In other ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required