Two different LINQ queries against the same Entity Framework DbSet, both return the same results
<p>Assuming I have:</p>

<pre><code>class ContractContext : DbContext
{
    DbSet&lt;ACTIVITY&gt; ACTIVITYs { get; set; }
}
</code></pre>

<p>And I have the following code, where startSnapshot and endSnapshot are integers with values 1 and 2:</p>

<pre><code>var activitiesStart = contractContext.ACTIVITYs.Where(a =&gt; a.VARIANCE_SNAPSHOT_ID == startSnapshot);
var activitiesEnd = contractContext.ACTIVITYs.Where(a =&gt; a.VARIANCE_SNAPSHOT_ID == endSnapshot);
</code></pre>

<p>Those two queries will return the same result. That result will be the result from the first one of those two queries that executes. So if I force them both to execute with a ToList(),</p>

<pre><code>var activitiesStart = contractContext.ACTIVITYs.Where(a =&gt; a.VARIANCE_SNAPSHOT_ID == startSnapshot).ToList();
var activitiesEnd = contractContext.ACTIVITYs.Where(a =&gt; a.VARIANCE_SNAPSHOT_ID == endSnapshot).ToList();
</code></pre>

<p>Then the result stored in activitiesEnd will be the result from the activitiesStart query. If I execute the activitiesEnd query first then the opposite will be true. What's going on? I understand that they are the same context, and I guess I can see how it <em>might</em> combine the queries if I create them both before either is executed. In the second case, however, one is executed before the other is even created so why is it trampling the second query?</p>

<p>Generated SQL (same for both):</p>

<pre><code>{SELECT 
    [Extent1].[ACTIVITY_ID] AS [ACTIVITY_ID], 
    [Extent1].[ACTIVITY_NAME] AS [ACTIVITY_NAME], 
    [Extent1].[WBS_ID] AS [WBS_ID], 
    [Extent1].[VARIANCE_SNAPSHOT_ID] AS [VARIANCE_SNAPSHOT_ID], 
    [Extent1].[DUE_DATE] AS [DUE_DATE], 
    [Extent1].[IS_COMPLETE] AS [IS_COMPLETE]
FROM [p6].[ACTIVITY] AS [Extent1]
WHERE [Extent1].[VARIANCE_SNAPSHOT_ID] = @p__linq__0}
</code></pre>

<h1>Example</h1>

<pre><code>var activitiesStart = contractContext.ACTIVITYs.Where(a =&gt; a.VARIANCE_SNAPSHOT_ID == 1).ToList();
var activitiesEnd = contractContext.ACTIVITYs.Where(a =&gt; a.VARIANCE_SNAPSHOT_ID == 2).ToList();

foreach (var item in activitiesStart)
{
    Debug.Write(item.VARIANCE_SNAPSHOT_ID + " ");
}

Debug.WriteLine("");

foreach (var item in activitiesEnd)
{
    Debug.Write(item.VARIANCE_SNAPSHOT_ID + " ");
}

Debug.WriteLine("");
</code></pre>

<p>This prints out two rows of ones, because activitiesStart was executed first. If I swap them I get two rows of twos. The SQL Server Profiler shows that the queries were properly sent to the server.</p>