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 words, the actual query command is sent to the database when the results of that LINQ query are accessed or enumerated. Entity Framework is doing so based on the IQueryable
interface that DbSet
implements. We can enumerate the results of our query...