Why does Entity Framework 6.x not cache results?

后端 未结 6 1237
生来不讨喜
生来不讨喜 2020-12-04 16:56

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

6条回答
  •  有刺的猬
    2020-12-04 17:26

    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, or ToList.
    • LINQ operators such as First or Any are specified in the outermost part of the query.
    • The following methods are called: the Load extension method on a DbSet, DbEntityEntry.Reload, and Database.ExecuteSqlCommand.

提交回复
热议问题