Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF6 equivalent of EF Core's QueryTrackingBehavior.NoTracking

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.

like image 494
GregH Avatar asked Sep 19 '17 18:09

GregH


1 Answers

No, there is no similar functionality in EF6

like image 200
ErikEJ Avatar answered Sep 26 '22 14:09

ErikEJ