简体   繁体   English

实体框架6缓存查询结果?

[英]Entity framework 6 cache query result?

I have a problem during development test, but also in pre-production environment (and so, i suppose in production too). 我在开发测试期间遇到了问题,但在预生产环境中也有问题(因此,我认为在生产环境中也是如此)。

Everytime I modify a data directly on database (from outside my application), it's like my application do not see any change and still retrieve old data. 每次我直接在数据库上修改数据(从我的应用程序外部),就像我的应用程序看不到任何更改,仍然检索旧数据。 Of course, I do commit. 当然,我确实承诺。 My application use EF6.1.3. 我的应用程序使用EF6.1.3。 I thought EF had a cache o something like that. 我以为EF有这样的缓存。 But I read: 但我读到:

Entity Framework does not currently support caching of query results. 实体框架目前不支持查询结果的缓存。 A sample EF Caching provider is available for Entity Framework version 5 and earlier but due to changes to the provider model this sample provider does not work with Entity Framework 6 and newer. 实例框架版本5及更早版本可以使用示例EF缓存提供程序,但由于对提供程序模型的更改,此示例提供程序无法与Entity Framework 6及更高版本一起使用。

So if it is not EF cache what can be and how can I solve? 所以,如果它不是EF缓存可以是什么,我该如何解决?

I know in production environment I will not change data directly from db, but in future we are going to develope another application will use the same database and the same data. 我知道在生产环境中我不会直接从db更改数据,但是将来我们将开发另一个应用程序将使用相同的数据库和相同的数据。

Thank you 谢谢

This is probably because Configuration.AutoDetectChangesEnabled was set to false in your database context. 这可能是因为Configuration.AutoDetectChangesEnabled在数据库上下文中设置为false This should be true by default, I think you should check in the constructor first before you do this in your context's constructor. 默认情况下应该是这样,我认为在上下文的构造函数中执行此操作之前,应首先检查构造函数。
Configuration.AutoDetectChangesEnabled = true;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM