Perhaps I am misunderstanding the caching that DbContext
and DbSet
does but I was under the impression that there was some caching that would go on
Take a look at EF Docs, you will find answer there:
Note that DbSet and IDbSet always create queries against the database and will always involve a round trip to the database even if the entities returned already exist in the context. A query is executed against the database when:
- It is enumerated by a foreach (C#) or For Each (Visual Basic) statement.
- It is enumerated by a collection operation such as
ToArray
,ToDictionary
, orToList
.- LINQ operators such as
First
orAny
are specified in the outermost part of the query.- The following methods are called: the
Load
extension method on aDbSet
,DbEntityEntry.Reload
, andDatabase.ExecuteSqlCommand
.