DbContext ChangeTracking kills performance?

Is the technique at the end of this documentation useful? Alternatively, I’ve avoided many of the performance pitfalls using a fluent interface to declaratively state which entities in a given transaction for sure won’t change vs. might change (immutable vs. immutable). For example, if the entities I am saving are aggregate roots in which the … Read more

Entity Framework 4.1+ many-to-many relationships change tracking

Here is how to find all the changed many-to-many relationships. I’ve implemented the code as extension methods: public static class IaExtensions { public static IEnumerable<Tuple<object, object>> GetAddedRelationships( this DbContext context) { return GetRelationships(context, EntityState.Added, (e, i) => e.CurrentValues[i]); } public static IEnumerable<Tuple<object, object>> GetDeletedRelationships( this DbContext context) { return GetRelationships(context, EntityState.Deleted, (e, i) => e.OriginalValues[i]); … Read more

Turn off EF change tracking for any instance of the context [duplicate]

Try changing your context constructor to this: public ReportingContext() { this.Configuration.AutoDetectChangesEnabled = false; } EDIT: 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/secrets-of-detectchanges-part-3-switching-off-automatic-detectchanges/

Global setting for AsNoTracking()?

Since this question is not tagged with a specific EF version, I wanted to mention that in EF Core the behavior can be configured at the context level. You can also change the default tracking behavior at the context instance level: using (var context = new BloggingContext()) { context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; var blogs = context.Blogs.ToList(); … Read more

tech