问题描述
提供了一些证据表明,在实体框架数据上下文中关闭AutoDetectChanges可以在插入大量实体时提供显着的性能提升。
This article provides some evidence that turning off AutoDetectChanges on your Entity Framework data context can provide a significant performance improvement when inserting large numbers of entities.
context.Configuration.AutoDetectChangesEnabled = false;
但是,由似乎没有提供任何方式来控制此设置。
However, the DataContext provided by the SqlEntityConnection type provider doesn't seem to provide any way to control this setting.
没有 context.Configuration
属性,或 context.DataContext.Configuration
属性。有一个 context.DataContext.ContextOptions
,但它甚至没有甚至类似于 AutoDetectChangesEnabled
。
There's no context.Configuration
property, or context.DataContext.Configuration
property. There is a context.DataContext.ContextOptions
but it has nothing even resembling AutoDetectChangesEnabled
.
类型提供者上下文中的 DataContext
属性类型为。有人知道有什么办法影响这个特定的设置吗?
The DataContext
property on the type provider context is of type System.Data.Objects.ObjectContext
. Does anyone know of a way to influence this particular setting from there?
推荐答案
去年,我写了一个非常类似的文章,您可以在这里找到的性能:我的经验主要是使用DbContext(它包装ObjectContext),但是我做了一些搜索,发现以下
I wrote a pretty similar article last year on detect changes performance which you can find here: http://blog.staticvoid.co.nz/2012/5/7/entityframework_performance_and_autodetectchanges My experience is mostly with DbContext (which wraps ObjectContext) but i did a bit of a search and found the following
这是什么意思,ObjectContext实际上并没有做自动更改检测,所以这不是你应该担心的事情。然而,您仍然需要注意,大型对象图将会减慢事情的发生,因为所有快照跟踪方案都会在某些时候检测到需要更改,这涉及到对象图的完整枚举
what this says is that ObjectContext doesnt actually do automatic change detection so this isnt something you should need to worry about. However you still do need to be aware that large object graphs will slow things down as is all snapshot tracking scenarios detect changes is required at some point, and this involves full enumeration of the object graph
这篇关于有没有办法控制SqlEntityConnection上的AutoDetectChanges?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!