My understanding of the Entity Framework is that if it can answer a query from its cache, it will. My simple testing, however, shows repeated queries hit the database even though they were previously answered positively:
var u1 = context.Users.SingleOrDefault(u => u.Id == 1);
var u2 = context.Users.SingleOrDefault(u => u.Id == 1);
These queries are successful. For each, I see a SELECT TOP (2)
in SQL Profiler.
Why does EF go to the database for that second query?