如何清除或忽略所有实体框架缓存一次? [英] How to clear or ignore all entity framework cache one time ?

查看:93
本文介绍了如何清除或忽略所有实体框架缓存一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我写了一个软件(大约200个表格的大型软件在网络上运行),每个表格都有很多查询。



现在我需要清除EF6缓存。我需要从数据库加载数据,而不是上下文缓存。





清除此缓存的简单方法是什么?有没有什么方法可以将它一次性应用到EF以上,而不是以所有形式重复它?



我尝试过:



i搜索并找到了这些方法,但所有这些方法都不适合应用一次且难以执行多次。



使用AsNoTracking禁用跟踪()

丢弃DbContext并创建一个新的

使用ObjectQuery而不是DBQuery并设置MergeOptions

刷新实体

分离实体

调用GetDatabaseValues以获取单个实体的更新值



I write a software ( huge software about 200 form which works on a network ), every form have Many queries.

now I need to clear EF6 cache. I need to load data from database, not context cache.


what is the easy and time-saving way to clear this cache? there is any method to apply it to all over EF one time without repeating it in all forms?

What I have tried:

i searched and found these methods but all of them Not suitable for applied once and difficult to carry out many times.

Disable Tracking using AsNoTracking()
Throw away the DbContext and create a new one
Use an ObjectQuery instead of a DBQuery and set MergeOptions
Refresh the Entities
Detach the Entities
Call GetDatabaseValues to get the updated values for a single Entity

推荐答案

这个问题让我想知道你是如何创建一个DbContext实例并使用它的。 清除缓存只是处理上下文实例并创建另一个实例。



你当然不应该创建一个DbContext实例而只是保持它为申请的有效期。
This question makes me wonder how you're creating a DbContext instance and using it. To "clear the cache" is to just Dispose the context instance and create another one.

You most certainly should NOT create a DbContext instance and just hold onto it for the lifetime of your application.


这篇关于如何清除或忽略所有实体框架缓存一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆