someone knows how to disable the AutoDetectChanges on EFCore?
I need to do it because I have to make an huge import in my database, and can't find information on web.
Tried this but it's not working:
_context.Configuration.AutoDetectChangesEnabled = false;
Say configuration does not exist.
Thanks a lot.
In Entity Framework, change tracking is enabled by default. You can also disable change tracking by setting the AutoDetectChangesEnabled property of DbContext to false. If this property is set to true then the Entity Framework maintains the state of entities.
AutoDetectChangesEnabled to false should disable change tracking requiring one to call DbContext. DetectChanges in order to identify changes to be sent to the database.
Detect Changes works by detecting the differences between the current property values of the entity and the original property values that are stored in a snapshot when the entity was queried or attached. The techniques shown in this topic apply equally to models created with Code First and the EF Designer.
What you have tried
_context.Configuration.AutoDetectChangesEnabled = false;
is for EF6.
The corresponding EF Core option AutoDetectChangesEnabled is property of the ChangeTracker associated with the DbContext, so the corresponding code is
_context.ChangeTracker.AutoDetectChangesEnabled = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With