关闭EF更改跟踪的情况下的任何实例 [英] Turn off EF change tracking for any instance of the context
问题描述
我有一个背景下,为报告只读数据库和我编写大量的代码,如:
I have a context to a read-only database for reporting and I am writing lots of code, like this:
using (var context = new ReportingContext())
{
var reportXQuery = context.ReportX.AsNoTracking();
// Do stuff here with query...
}
有没有一种方法来设置 AsNoTracking
位,所以只新
ING了 ReportingContext
上面会自动使用 AsNoTracking
,而不是需要记住显式调用它的每一个查询?
Is there a way to set the AsNoTracking
bit so that just new
ing up the ReportingContext
above would automatically use AsNoTracking
instead of needing to remember to explicitly call it every query?
推荐答案
试着改变你的环境构造这样:
Try changing your context constructor to this:
public ReportingContext()
{
this.Configuration.AutoDetectChangesEnabled = false;
}
编辑:
这会毕竟不是帮你,亚瑟的博客的声明,它是可用的只在特定的情景:
This will after all not help you, as stated on Arthur's blog, it is usable only in particular scenarios:
的 http://blog.oneunicorn.com / 2012/03/12 /秘密-OF-detectchanges部分-3-开关关闭,自动detectchanges /
这篇关于关闭EF更改跟踪的情况下的任何实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!