<p>Speaking as a non-C# savvy programmer, I'm curious as to the evaluation semantics of LINQ queries like the following:</p>

<pre><code>var people = from p in Person
             where p.age &lt; 18
             select p

var otherPeople = from p in people
                  where p.firstName equals "Daniel"
                  select p
</code></pre>

<p>Assuming that <code>Person</code> is an ADO entity which defines the <code>age</code> and <code>firstName</code> fields, what would this do from a database standpoint?  Specifically, would the <code>people</code> query be run to produce an in-memory structure, which would then be queried by the <code>otherPeople</code> query?  Or would the construction of <code>otherPeople</code> merely pull the data regarding the query from <code>people</code> and then produce a new database-peered query?  So, if I iterated over both of these queries, how many SQL statements would be executed?</p>

```
people
```
and
```
otherPeople
```
contain objects of type
```
IQueryable<Person>
```
.
If you iterate over both, separatly, it will run two queries.
If you only iterate over
```
otherPeople
```
, it will run the expected query, with two where clauses.
If you do
```
.ToList()
```
on
```
people
```
and use the returned
```
List<Person>
```
in the second query instead of people, it becomes LINQ-to-Objects and no SQL is executed.
This behavior is referred to as deferred execution. Meaning no query is done until it is needed. Before execution they are just expression trees that get manipulated to formulate the final query.