Is there any way to control AutoDetectChanges on SqlEntityConnection?

北城以北 提交于 2019-12-10 15:48:37

问题


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.

There's no context.Configuration property, or context.DataContext.Configuration property. There is a context.DataContext.ContextOptions but it has nothing even resembling AutoDetectChangesEnabled.

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?


回答1:


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

Why is inserting entities in EF 4.1 so slow compared to 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



来源:https://stackoverflow.com/questions/14130729/is-there-any-way-to-control-autodetectchanges-on-sqlentityconnection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!