I am searching for a way to globally disable change tracking in my Context
class. This will prevent developers from forgetting to put .AsNoTracking()
on each repository query as we currently do. This will also prevent us from manually having to .Detach()
entities on occasion. I have found a solution in EF Core which is to do something like the following:
public class MyContext : DbContext
{
public MyContext() {
ChangeTracker.QueryTrackingBehavior =
QueryTrackingBehavior.NoTracking;
}
public DbSet<MyEntity> MyEntities {get;set;}
}
However, the Context
class in Entity Framework 6 does not appear to have a QueryTrackingBehavior
property on it's ChangeTracker
. Is there a way to accomplish this using Entity Framework 6?
Please note that I have already looked into using AutoDetectChangesEnabled = false
and it does not work for the reasons outlined here.
All help is appreciated.
No, there is no similar functionality in EF6
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